开发者

UIImageView animation: manual frame advance

I am developing an iPhone app with a UIImageView. The UIImageView is populated from an NSArray. What I would like to know, is how to, instead of using the

[imageView startAnimating];

call,开发者_开发问答 how can I use a UIButton to advance between images?

here is my viewDidLoad:

- (void)viewDidLoad
{
    imageView.animationImages = [NSArray arrayWithObjects:
                                 [UIImage imageNamed:@"1.png"],
                                 [UIImage imageNamed:@"2.png"],
                                 [UIImage imageNamed:@"3.png"],
                                 nil];
;    imageView.animationDuration = 10.00;
    imageView.animationRepeatCount = 0;
    [imageView startAnimating];
    [super viewDidLoad];
    [self.view addSubview:imageView];

}

Also, I would like to know how to, based on this code, how to when the app starts, have the ImageView on image 1.png?

Thanks all.


You can't. [UIImage animationImages] is meant for an animation, not a slideshow-type effect. It's meant for your own implementations of UIActivityIndicator for instance.


Just keep an array of your UIImages handy and change the UIImageView's image property on each button press. Something like this perhaps:

// ivars
NSUInteger imageIndex;
NSArray *images;

// initialization
images = [[NSArray arrayWithObjects:
                                 [UIImage imageNamed:@"1.png"],
                                 [UIImage imageNamed:@"2.png"],
                                 [UIImage imageNamed:@"3.png"],
                                 nil] retain];
imagesIndex = 0;
imageView.image = [images objectAtIndex:imagesIndex];

and in the button's action method:

- (void)someAction:(id)sender {
  imagesIndex = (imagesIndex + 1) % [images count];
  imageView.image = [images objectAtIndex:imagesIndex];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜