使用UIDocumentInteractionController时隐藏状态栏? [英] Hide status bar when using UIDocumentInteractionController?

查看:84
本文介绍了使用UIDocumentInteractionController时隐藏状态栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要查看/共享PDF文件的React Native应用.我使用的是

解决方案

另一种hacky解决方案:

 静态NSTimer * timer = nil;-(void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller{计时器= [NSTimercheduledTimerWithTimeInterval:0.1重复:是块:^(NSTimer * __Nonnull计时器){[[UIApplication sharedApplication] setStatusBarHidden:YES];}];}-(void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)控制器{[计时器无效];} 

您可以将 timer 定义放置在所需的任何位置,只需确保在关闭预览后使它无效即可.我还注意到,如果将带有 setStatusBarHidden:YES 的行放在if子句中,在其中检查它是否实际上是隐藏的,则此解决方案将不再起作用.似乎是 UIDocumentInteractionController 中的错误.

I'm working on an React Native app that needs to view/share PDF files. I'm use the react-native-open-file module which uses the UIDocumentInteractionController to view PDF files. When the PDF file is opened the status bar appears over the PDF. My app has the staus bar hidden at all times. How do I hide the status bar when viewing the PDF?

Here's the code from the module:

//
//  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

I was able to add a documentInteractionControllerDidEndPreview method that hides the status after it closes but I would rather never have the status bar open at all:

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

Update:

Here's a picture of the status bar over the menu bar:

解决方案

Another hacky solution:

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];
}

You can put the timer definition anywhere you want, just make sure to invalidate it once you close the preview. I have also noticed that if you put the line with setStatusBarHidden:YES inside an if clause where you check if it is actually hidden, this solution no longer works. It seems like a bug in UIDocumentInteractionController.

这篇关于使用UIDocumentInteractionController时隐藏状态栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆