2013-06-18 78 views
1

我在SO看过几个与此相关的问题,但他们都没有回答这个问题:delay部分UIViewanimateWithDuration:delay:options:animate:completion:不会延迟。下面是调用它的实际代码:UIView animateWithDuration:delay:options:animate:completion not undelaying

-(void) viewDidAppear:(BOOL)animated 
{ 
    NSLog(@"about to start animateWithDuration..."); 

    [UIView animateWithDuration:3.0 delay:2.0 options:UIViewAnimationOptionTransitionNone 
        animations:^{NSLog(@"in the animations block..."); self.textView.hidden = YES;} 
        completion:^(BOOL finished){if (finished) {NSLog(@"In the completion block..."); self.textView.hidden = NO; [self.player play];}}]; 
} 

这里是NSLog时间戳:

2013年6月18日15:27:16.607 AppTest1 [52083:C07]即将开始animateWithDuration。 ..

2013年6月18日15:27:16.608 AppTest1 [52083:C07]在动画块...

2013年6月18日15:27:16.609 AppTest1 [52083:C07在完成块...

正如人们可以看到的那样,指令的执行时间为毫秒,而不是延迟2或3秒。有人会知道这个原因吗?

回答

7

hidden属性不是动画:

UIView类的以下属性动画:

@property frame

@property bounds

@property center

@property transform

@property alpha

@property backgroundColor

@property contentStretch

尝试在你的动画块使用这些属性之一,然后应该会出现延迟。例如,您可以将alpha1.0动画到0.0,然后将其隐藏在完成块中。

+0

感谢您的快速回复!我也通过不使用animateWithDuration完成了工作:完全可以使用[self performSelector:@selector(doneMethod)withObject:nil afterDelay:0.5]; – user2491253