Should I use a GIF file or animation code in iOS?

I intend to make a screensaver on iOS consisting of a person, a chair object. Each of these objects has separate aspects, such as hands, head, body and legs, which are animated together. I wonder where better to go? Import GIF file or encode CALayer objects and then add animation?

+4
source share
2 answers

You cannot use GIF files or any animation code for your launcher (splash screen), you can only use a static image, PNG or JPG (if the booster is a storyboard).

So, if you want your application to run with some animation, you have to control it in your first view controller.

You can animate imageviewwith sets of images, for example,

UIImageView* myImageViewForAnimation = [[UIImageView alloc] initWithFrame:self.view.bounds];
myImageViewForAnimation.animationImages = [NSArray arrayWithObjects:
                                     [UIImage imageNamed:@"image1"],
                                     [UIImage imageNamed:@"image2"],
                                     [UIImage imageNamed:@"image3"],
                                     [UIImage imageNamed:@"image4"], nil];
myImageViewForAnimation.animationDuration = 1.0f;
myImageViewForAnimation.animationRepeatCount = 0;
[myImageViewForAnimation startAnimating];
[self.view addSubview: myImageViewForAnimation];

Update (as indicated in the comment):

You can get your idea by which you added gesture recognizeractions to your method, or you can set tagfor each imageviewand process it in the action method.

For instance,

 -(void)tapOnProfileImage : (UITapGestureRecognizer*)recog{


UIImageView *tempView = (UIImageView *)recog.view;

// or

if (recog.view.tag == 1) {

    // image 1
}

if (recog.view.tag == 2) {
    //image 2
}
}

So, on each representation of the image, you must add target with selector - tapOnProfileImage, and you can distinguish it, as indicated in the code snippet above!

+6
source
+2

Source: https://habr.com/ru/post/1655938/


All Articles