【发布时间】:2011-05-20 19:08:39
【问题描述】:
按下按钮后,我需要在两张(或以后更多)图片之间切换特定的次数,然后等待一两秒钟进行更改。在任何时候按下停止按钮时,切换应该停止。我的代码现在看起来像这样
IBOutlet UIImageView *exerciseView;
- (void) repetitionCycle {
stopButtonPressed = NO;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for (NSInteger counter = kRepetitions; counter >=0; counter--) {
exerciseView.image = [UIImage imageNamed:@"blue.jpg"];
[NSThread sleepForTimeInterval:kSleepDuration];
if (stopButtonPressed) {break;}
image = [UIImage imageNamed:kExerciseEndingPosition];
exerciseView.image = [UIImage imageNamed:@"image1.jpg"];
[NSThread sleepForTimeInterval:kSleepDuration];
if (stopButtonPressed) {break;}
}
self.stopRepetitionCycle;
[pool release];
}
exerciseView 是 除此之外,在 stopRepetitionCycle 中,我只是将 stopButtonPressed 设置为 YES,因此它在第一次完成“for”后停止。 它确实倒计时,它确实在一个周期后停止,但它不会改变画面。
在摆弄的时候,我通过 IB 设置了初始图片,所以它最终显示了 ANYTHING.. 有趣的部分,当我在正确的时刻按下停止按钮时,显示了第二张图片。所以我猜想每次图像切换时我都需要手动设置视图。但是
[self.exerciseView addSubview:image];
给我错误
Incompatible Objective-C types "struct UIImage *", expected "struct UIView *" when passing argument 1 of "addSubview:" from distinct Objective-C type
还有
[self.exerciseView.image addSubview:image];
不做这项工作并给我一个
UIImage may not respond to addSubview
知道我要在这里做什么吗?
非常感谢!
【问题讨论】:
标签: iphone objective-c animation uiimageview