0

所以这是我的代码:

- (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

但是,在调用 animateTurn 时NSTimer,动画不会显示。如果我通过正常调用该方法,[self animateTurn]那么它们会出现,但没有NSTimer也没有performSelector

对此有任何帮助(甚至建议更好的方法)?

编辑: 我应该提到该函数实际上正在被触发并且代码正在运行,包括 startAnimating(使用 BOOL/NSLog 检查)。根本没有显示任何内容。

4

2 回答 2

0

这是您的解决方案:-

这就是我使用的,现在选择器正在工作。:-)

  if (![NSThread isMainThread]) 
    { [self performSelectorOnMainThread:@selector(selectorToRunInMainThread) withObject:nil waitUntilDone:NO]; 
     }
 -(void)selectorToRunInMainThread
{
 NSString *str = @"Timer event has fired"; 
NSTimer *atimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateModel:) userInfo:str repeats:YES]; 
} 
于 2013-10-19T07:00:21.603 回答
-1

在你的计时器后面加上这一行:-

    [timer fire];
于 2013-10-19T08:42:15.223 回答