【发布时间】:2015-08-18 11:14:57
【问题描述】:
在以下代码中,NSTimer 间隔设置为每张图片之间的 1 秒。我的目标是将前两张图片 hello.png 和 bye.png 之后的间隔更改为 4 秒。
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *imageNames = @[@"hello.png",@"bye.png",@"helloagain.png",@"bye again"];
self.images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++) {
[self.images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}
self.animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 95, 86, 90)];
self.animationImageView.image = self.images[0];
[self.view addSubview:self.animationImageView];
self.animationImageView.userInteractionEnabled = TRUE;
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeImage:) userInfo:nil repeats:YES];
}
-(void)changeImage:(NSTimer *) timer {
if (counter == self.images.count - 1 ) {
counter = 0;
}else {
counter ++;
}
self.animationImageView.image = self.images[counter];
}
【问题讨论】:
标签: objective-c cocoa-touch nstimer intervals