【发布时间】:2013-10-28 02:18:02
【问题描述】:
这是我的代码:
- (IBAction)run:(id)sender {
animationPointer = 0;
self.animationArray = [[NSMutableArray alloc] init];
UIView *allViews = [[UIView alloc]
initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
for (int i = 0; i < [self.paths count]; i++) {
[allViews addSubview:[self createAnimation:[self.paths objectAtIndex:i]]];
[self.animationArray addObject:allViews];
}
timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(animateTurn)
userInfo:nil repeats:YES];
}
- (void)animateTurn {
UIView *tempView = [self.animationArray objectAtIndex:animationPointer];
[self.view addSubview:tempView];
for (UIImageView *view in tempView.subviews) {
[[tempView.subviews objectAtIndex:animationPointer] startAnimating];
}
animationPointer++;
if (animationPointer >= [self.animationArray count]) {
[timer invalidate];
}
}
createAnimation 如您所料,返回一个完全动画的UIImageView。计划是在每个UIView 上设置几个,然后在UIView 上为它们全部设置动画,然后在半秒后下一个并重复。目前每个UIView 上只有一个。
但是,在 NSTimer 上调用 animateTurn 时,动画不会显示。
如果我通过普通的[self animateTurn] 调用该方法,那么它们会出现,但NSTimer 和performSelector 函数都没有。
对此有任何帮助(甚至是更好的方法的建议)?
编辑: 我应该提到该函数实际上正在被触发并且代码正在运行,包括 startAnimating(使用 BOOL/NSLog 检查)。根本没有显示任何内容。
【问题讨论】:
-
您应该检查该方法是否在主线程上调用。
标签: ios objective-c animation nstimer