简体   繁体   English

iOS 9兼容版NSTimer scheduledTimerWithTimeInterval:重复:阻止:?

[英]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.

相关问题 自动锁定ios设备,NSTimer和scheduledTimerWithTimeInterval - autolocking ios device, NSTimer and scheduledTimerWithTimeInterval NSTimer ScheduledTimerWithTimeInterval:target:selector:userInfo:repeats不调用该方法 - NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats doesn't invoke the method NSTimer ScheduledTimerWithTimeInterval-不调用功能 - NSTimer scheduledTimerWithTimeInterval - not calling funciton 我可以使用NSTimer的ScheduledTimerWithTimeInterval方法1天(24小时)是否重复? - Can I use NSTimer's scheduledTimerWithTimeInterval method for 1 day (24 hour) with or without repeats? 如何停止NSTimer.scheduledTimerWithTimeInterval - How to stop NSTimer.scheduledTimerWithTimeInterval 如何完全删除NSTimer ScheduledTimerWithTimeInterval - How to remove NSTimer scheduledTimerWithTimeInterval entirely + [NSTimer timerWithTimeInterval:block:重复:]:发送给类的无法识别的选择器 - +[NSTimer timerWithTimeInterval:block:repeats:]: unrecognized selector sent to class ios scheduledTimerWithTimeInterval表示一段时间 - ios scheduledTimerWithTimeInterval for amount of time 在Objective-C中为scheduledTimerWithTimeInterval反转NSTimer - Reverse NSTimer for scheduledTimerWithTimeInterval in Objective-C dispatch_after 递归 vs NSTimer scheduledtimerwithtimeinterval - dispatch_after recursion vs NSTimer scheduledtimerwithtimeinterval
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM