因此,这里是我的代码:无法从的NSTimer的选择触发功能
- (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的检查)运行。根本没有显示。
您应该检查是否该方法被称为主线程。 – dasdom