[英]iOS 9 compatible version of NSTimer scheduledTimerWithTimeInterval:repeats:block:?
I'm using the following code in iOS 10 but when I run it in iOS 9 it crashes. 我在iOS 10中使用以下代码,但是当我在iOS 9中运行它时崩溃了。 I don't think NSTimer scheduledTimerWithTimeInterval:repeats:block: supports iOS 9. How can I implement a timer that will work in iOS 8 - 10?
我不认为NSTimer scheduledTimerWithTimeInterval:重复:块:支持iOS 9.如何实现可在iOS 8-10中运行的计时器?
static NSTimer* timer = nil;
- (void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller
{
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}];
}
-(void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
[timer invalidate];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
You appear to be using a function introduced in iOS10. 您似乎正在使用iOS10中引入的功能。 Further down the page you linked is a function that was in iOS 2.
您在链接的页面下方是iOS 2中的一个功能。
https://developer.apple.com/documentation/foundation/nstimer/1408356-timerwithtimeinterval?language=objc https://developer.apple.com/documentation/foundation/nstimer/1408356-timerwithtimeinterval?language=objc
Use that instead. 改用它。
This fixed it: 这解决了它:
static NSTimer* timer = nil;
- (void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller
{
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(hideStatusBar) userInfo:nil repeats:YES];
}
-(void)hideStatusBar
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
-(void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
[timer invalidate];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.