我在 iOS 10 中使用以下代码,但在 iOS 9 中运行时它崩溃了。我不认为NSTimer scheduledTimerWithTimeInterval:repeats:block:支持 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];
}
最佳答案
您似乎在使用 iOS10 中引入的功能。在您链接的页面的下方是 iOS 2 中的一个功能。
改用它。
关于iOS 9 兼容版本的 NSTimer scheduledTimerWithTimeInterval :repeats:block:?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45965895/