简体   繁体   中英

Animating UIImageView frame by frame

I have an idea about how to add animated UIImageView using frame by frame method BUT my question is about How to animate UIImageView ALREADY added on view controller storyboard as IBOutlet UIImageView .

what will be changed at this peace of code ?!

NSArray *myImages = [NSArray arrayWithObjects:
                         [UIImage imageNamed:@"bookmark1.png"],
                         [UIImage imageNamed:@"bookmark2.png"],
                         [UIImage imageNamed:@"bookmark3.png"],
                         [UIImage imageNamed:@"bookmark4.png"],
                         [UIImage imageNamed:@"bookmark5.png"],nil];

    myAnimatedView = [UIImageView alloc];

   [myAnimatedView initWithFrame:CGRectMake(0, 0, 131, 125)];

    myAnimatedView.animationImages = myImages;

    myAnimatedView.animationDuration = 0.25;

    myAnimatedView.animationRepeatCount = 1;

    [myAnimatedView startAnimating];

    [self.navigationController.view addSubview:myAnimatedView];

I want to animate this image like that over my viewController

http://imageshack.us/a/img717/3051/bookmarkl.gif

It's even easier. First, add in .h file:

@property (nonatomic, retain) IBOutlet UIImageView *iV;

After, connect this outlet to the actual UIImageView on your storyboard. Change your code:

iV.animationImages = myImages;
iV.animationDuration = 0.25;
iV.animationRepeatCount = 1;
[iV startAnimating];

And that's all. Hope this helped

ps And yes, don't forget iV = nil; in - (void)viewDidUnload method

UPD: added

[self performSelector:@selector(animationDone) withObject:nil afterDelay:0.25];

After startAnimating call, and obviously added animationDone method:

- (void)animationDone {
    [iV stopAnimating];
    [iV setImage:[UIImage imageNamed:@"bookmark5.png"]];
}

Well it will be pretty much the same. You dont need to allocate your image view [[UIImageView alloc] init] nor do you need to add it to the viewController. The rest is the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM