ios – 使用UIDocumentInteractionController隐藏状态栏?

前端之家收集整理的这篇文章主要介绍了ios – 使用UIDocumentInteractionController隐藏状态栏?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用一个需要查看/共享PDF文件的React Native应用程序.我使用的是使用UIDocumentInteractionController的 react-native-open-file模块来查看PDF文件.打开PDF文件时,PDF上将显示状态栏.我的应用程序始终保持隐藏.查看PDF时如何隐藏状态栏?

Here’s the code from the module

@H_404_4@// // RNDocumentInteractionController.m // RNDocumentInteractionController // // Created by Aaron Greenwald on 7/5/16. // Copyright © 2016 Wix.com. All rights reserved. // #import "RNDocumentInteractionController.h" #import <UIKit/UIKit.h> @implementation RNDocumentInteractionController RCT_EXPORT_MODULE(); RCT_EXPORT_METHOD(open: (NSURL *)path) { UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:path]; interactionController.delegate = self; [interactionController presentPreviewAnimated:YES]; } - (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller { return [[[[UIApplication sharedApplication] delegate] window] rootViewController]; } @end

我可以添加一个documentInteractionControllerDidEndPreview方法,该方法关闭状态后隐藏状态,但我宁愿永远不会打开状态栏:

@H_404_4@- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller { [[UIApplication sharedApplication] setStatusBarHidden:YES]; }

更新:

以下是菜单栏中状态栏的图片

解决方法

另一个黑客解决方案: @H_404_4@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]; }

您可以将定时器定义放在任何地方,只要您关闭预览,请确保无效.我也注意到,如果你在if子句中放置了setStatusBarHidden:YES,那么你检查它是否真的被隐藏,这个解决方案就不再有效了.这似乎是UIDocumentInteractionController中的一个错误.

猜你在找的iOS相关文章