2013-06-18 79 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