Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 332
Binh Le Avatar asked Feb 06 '23 01:02

Binh Le


1 Answers

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!

like image 124
Ketan Parmar Avatar answered Feb 08 '23 16:02

Ketan Parmar