6

UIDocumentInteractionController似乎无法与新的 iOS 7 状态栏正确交互,尤其是在横向上。我现在用于显示查看器的代码:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"pdf"];
    NSURL *url = [NSURL fileURLWithPath:filePath];

    UIDocumentInteractionController *pdfViewer = [UIDocumentInteractionController interactionControllerWithURL:url];
    [pdfViewer setDelegate:self];
    [pdfViewer presentPreviewAnimated:YES];
}

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    return self;
}

- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
{
    return self.view;
}

当交互控制器首次出现时,状态栏与标题重叠。

在此处输入图像描述

旋转到另一侧的横向暂时修复了该行为。

在此处输入图像描述

正如预期的那样,点击文档本身可以关闭框架。但是,一旦再次点击文档以激活框架,就会再次发生重叠,就像第一张图像一样。

我试过设置documentInteractionControllerRectForPreview无济于事。

- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller
{
    return CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height);
}

我不希望在交互控制器出现时隐藏状态栏,并且我认为可以正确执行此操作,因为 Mail 应用程序行为正确并且看起来它使用的是同一个类。

为任何想要使用代码的人附加的最小示例项目: https ://hostr.co/PiluL1VSToVt

4

4 回答 4

0

找到了新的解决方案。

在 info.plist 文件中为 iOS 7 添加这个: UIViewControllerBasedStatusBarAppearance (View controller-based status bar appearance) = NO

于 2013-11-22T07:06:54.657 回答
0

这些解决方案对我不起作用。我发现的唯一解决方案是在委托请求呈现视图控制器后强制状态栏在下一个运行循环中可见(也需要将 UIViewControllerBasedStatusBarAppearance 设置为 NO):

- (UIViewController *) documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *) controller {
    // hack to keep status bar visible
    [[NSOperationQueue mainQueue] addOperationWithBlock:
     ^{
         [[UIApplication sharedApplication] setStatusBarHidden:NO];
     }];
    return self.viewController;
}
于 2014-06-27T09:45:36.580 回答
0

我通过包装UIDocumentInteractionControlleraUINavigationController并将应用程序窗口的根视图控制器切换到导航控制器进行演示来解决了这个问题。在我的使用中,其他视图控制器没有使用UINavigationController,因此在解雇时我们将旧的根控制器换回:

#import "MainViewController.h"

@interface MainViewController ()

@property (nonatomic, strong) UINavigationController *navController;
@property (nonatomic, strong) MainViewController *main;

@end

@implementation MainViewController

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    self.main = self;
    self.navController = [[UINavigationController alloc] initWithRootViewController:[UIViewController new]];
    [[UIApplication sharedApplication].keyWindow setRootViewController:self.navController];

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"pdf"];
    NSURL *url = [NSURL fileURLWithPath:filePath];

    UIDocumentInteractionController *pdfViewer = [UIDocumentInteractionController interactionControllerWithURL:url];
    [pdfViewer setDelegate:self];
    [pdfViewer presentPreviewAnimated:YES];
}

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    return self.navController;
}

- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
    [[UIApplication sharedApplication].keyWindow setRootViewController:self.main];
    self.main = nil;
}

- (void)dismiss
{
    [self.navController popViewControllerAnimated:YES];
}

@end

虚拟视图控制器允许弹出交互控制器(后退按钮)。

于 2013-11-05T13:06:44.857 回答
0

试试下面的代码它对我有用:

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

- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
}
于 2015-08-26T11:38:15.050 回答