ios – 使用UIDocumentInteractionController隐藏状态栏?

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

Here’s the code from the module

  1. //
  2. // RNDocumentInteractionController.m
  3. // RNDocumentInteractionController
  4. //
  5. // Created by Aaron Greenwald on 7/5/16.
  6. // Copyright © 2016 Wix.com. All rights reserved.
  7. //
  8.  
  9. #import "RNDocumentInteractionController.h"
  10. #import <UIKit/UIKit.h>
  11.  
  12. @implementation RNDocumentInteractionController
  13.  
  14. RCT_EXPORT_MODULE();
  15.  
  16. RCT_EXPORT_METHOD(open: (NSURL *)path)
  17. {
  18. UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:path];
  19. interactionController.delegate = self;
  20. [interactionController presentPreviewAnimated:YES];
  21. }
  22.  
  23. - (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller
  24. {
  25. return [[[[UIApplication sharedApplication] delegate] window] rootViewController];
  26. }
  27.  
  28.  
  29. @end

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

  1. - (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
  2. {
  3. [[UIApplication sharedApplication] setStatusBarHidden:YES];
  4. }

更新:

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

解决方法

另一个黑客解决方案:
  1. static NSTimer* timer = nil;
  2. - (void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller
  3. {
  4. timer = [NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) {
  5. [[UIApplication sharedApplication] setStatusBarHidden:YES];
  6. }];
  7. }
  8.  
  9. -(void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
  10. {
  11. [timer invalidate];
  12. }

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

猜你在找的iOS相关文章