2013-09-29 126 views
7

我試圖在我的應用程序中實現截圖的一種方式。我想讓UINavigationBar提示向上滑動 - 截取屏幕截圖 - 然後UINavigationBar可以順暢地滑動。我需要的應用程序等待/保持一些代碼行之間的幾秒鐘,因爲這樣一來的第一個動畫沒有得到時間來完成:在執行代碼之前讓應用程序等待幾秒鐘?

[self.navigationController setNavigationBarHidden:YES animated:YES ]; 
[self.navigationController setNavigationBarHidden:NO animated:YES]; 

那麼,有沒有延緩執行的,就像當動畫的方式像這樣一個按鈕:

[UIView animateWithDuration:0.5 delay:3 options:UIViewAnimationOptionCurveEaseOut animations:^{self.myButton.frame = someButtonFrane;} completion:nil]; 

問候

回答

3

您可以使用:

[self performSelector:@selector(hideShowBarButton) withObject:nil afterDelay:1.0]; 

,當然:

- (void) hideShowBarButton{ 
    if (self.navigationController.navigationBarHidden) 
     [self.navigationController setNavigationBarHidden:NO animated:YES ]; 
    else 
     [self.navigationController setNavigationBarHidden:YES animated:YES ]; 
} 
0

雖然似乎沒有成爲setNavigationBarHidden的完成回調,將採取UINavigationControllerHideShowBarDuration秒。因此,只使用一個NSTimer推遲它:

[NSTimer scheduledTimerWithTimeInterval:UINavigationControllerHideShowBarDuration target:self selector:@selector(myFunction:) userInfo:nil repeats:NO]; 

您可能需要添加少量的延遲故障安全;

[NSTimer scheduledTimerWithTimeInterval:UINavigationControllerHideShowBarDuration+0.05 target:self selector:@selector(myFunction:) userInfo:nil repeats:NO]; 

又見此相關的問題:UINavigationControoller - setNavigationBarHidden:animated: How to sync other animations

11

您可以使用:

double delayInSeconds = 2.0; // number of seconds to wait 
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); 
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
    /*********************** 
    * Your code goes here * 
    ***********************/ 
});  
相關問題