Search code examples
iphonesdkcore-animation

Should I animate a three dots loading animation using Core Animation or should I find a way to show a gif of the same operation?


Basically I have three dots that are supposed to get bigger and smaller in succession on the loading screen and I'm wondering what is the best way to do a simple animation like that - coding or otherwise?


Solution

  • For a simple animation you can use a UIImageView animation to animate a set of images (i.e. use the images as frames in the animation).

    UIImageView* dotsImageView= [[UIImageView alloc] initWithFrame:dotsFrame];
    
    // load all the frames of your animation
    dotsImageView.animationImages = @[[UIImage imageNamed:@"image1.png"],
                                      [UIImage imageNamed:@"image2.png"],
                                      [UIImage imageNamed:@"image3.png"]];
    
    // set how long it will take to go through all images 
    dotsImageView.animationDuration = 1.0;
    // repeat the animation forever
    dotsImageView.animationRepeatCount = 0;
    // start the animation
    [dotsImageView startAnimating];
    // add it to the view
    [self.view addSubview:dotsImageView];
    

    If you don't want to use preset images for the dots, you can chain together UIView animations using the completion block. Here's a tutorial on UIView animations: http://www.raywenderlich.com/5478/uiview-animation-tutorial-practical-recipes