Thanh Nguyen Thanh Nguyen - 2 months ago 18
iOS Question

Should I use GIF file or animation code on iOS?

I intend to make a splash screen on iOS consists of a person, a chair objects. Each of these objects has seperated aspects like the hands, head, body and feets that animated together. I wonder which is better way to go? Importing a GIF file or coding CALayer objects then adding animation?

Answer

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

So, if you want your app's startup with some animation then you should manage it in your first view controller.

You can animate imageview with image sets like,

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 asked in comment) :

You can get your view on which you have added gesture recognizer in your action method or you can set tag to every imageview and handle it in action method.

For example,

 -(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 every image view, you should add target with selector - tapOnProfileImage and you can differentiate it as mentioned in above code snippet!

Comments