文档交互控制器与iOS 7状态栏? [英] Document interaction controller with iOS 7 status bar?

查看:163
本文介绍了文档交互控制器与iOS 7状态栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIDocumentInteractionController 似乎无法正常与新的iOS 7状态列正常交互,特别是在横向。现在显示查看器的代码:

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

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

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

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

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

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



>



在另一边旋转到横向可暂时修正此行为。





如预期点击文档本身可以关闭框架。



我已经尝试过设置 documentInteractionControllerRectForPreview

code>无效。

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



我不想在交互控制器启动时隐藏状态栏我假设这是可能正确做到这一点,因为Mail应用程序的行为正确,它看起来像使用相同的类。



一个最小的示例项目,使用代码:
https://hostr.co/PiluL1VSToVt

$我通过将 UIDocumentInteractionController 包装在 UINavigationController 中解决了这个问题。 / code>并将应用程序窗口的根视图控制器切换到导航控制器进行显示。在我的使用中,其他视图控制器没有使用 UINavigationController 所以一旦解雇我们交换旧的根控制器:

  #importMainViewController.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:@exampleofType:@pdf];
NSURL * url = [NSURL fileURLWithPath:filePath];

UIDocumentInteractionController * pdfViewer = [UIDocumentInteractionControllerinteractionControllerWithURL: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

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


The UIDocumentInteractionController seems to have trouble interacting properly with the new iOS 7 status bar particularly in landscape orientation. The code I have for displaying the viewer right now:

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

When the interaction controller first appears the status bar overlaps the title.

Rotating to landscape on the other side fixes the behaviour temporarily.

As expected tapping on the document itself allows dismisses the frame. However once the document is tapped once more to activate the frame the overlap occurs again as with the first image.

I have tried setting documentInteractionControllerRectForPreview to no avail.

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

I do not wish to hide the status bar when the interaction controller comes up and I assume it is possible to do this correctly since the Mail app behaves correctly and it looks like it is using the same class.

A minimal example project attached for anyone who wants to play with the code: https://hostr.co/PiluL1VSToVt

解决方案

I solved this by wrapping the UIDocumentInteractionController in a UINavigationController and switching the application window's root view controller to the navigation controller for presentation. In my usage the other view controllers were not using UINavigationController so upon dismissal we swap the old root controller back:

#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

The dummy view controller allows the interaction controller to be popped (back button).

这篇关于文档交互控制器与iOS 7状态栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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