我想运行一系列带对话框气泡的图片(如条形卡通片)。我试图使用这个动作:
-(IBAction) runDialog:(id)sender {
imageView.image = [UIImage imageNamed:@"a1.png"];
[NSThread sleepForTimeInterval:5.0];
imageView.image = [UIImage imageNamed:@"b1.png"];
[NSThread sleepForTimeInterval:5.0];
imageView.image = [UIImage imageNamed:@"b2.png"];
[NSThread sleepForTimeInterval:5.0];
imageView.image = [UIImage imageNamed:@"a2.png"];
[NSThread sleepForTimeInterval:5.0];
}
这不起作用。它只是显示最后一张图像(a2.png)约20秒后 任何想法我应该怎么做:显示一系列暂停之间的图片?
答案 0 :(得分:2)
改为使用NSTimer。
- (IBAction)runDialog:(id)sender {
yourInstanceVariableOfNSTimer = [NSTimer scheduledTimerWithTimeInterval:5.0f
target:self selector:@selector(showNextPage) userInfo:nil repeats:NO];
}
- (void)showNextPage {
imageView.image = [yourInstanceVariableOfNSArray
objectAtIndex:++yourInstanceVariableOfNSInteger];
if (!transitionsFinished) {
yourInstanceVariableOfNSTimer = [NSTimer scheduledTimerWithTimeInterval:5.0f
target:self selector:@selector(showNextPage) userInfo:nil repeats:NO];
}
}
答案 1 :(得分:2)
一种更简单的方法是在对话框中使用UIImageView并设置其animationImages,animationDuration等属性。