2013-09-29 60 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 * 
    ***********************/ 
});  
相关问题