Mik*_*wan 6 cocoa-touch statusbar ios uidocumentinteraction ios7
在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;
}
Run Code Online (Sandbox Code Playgroud)
当交互控制器首次出现时,状态栏与标题重叠.

在另一侧旋转到横向可以暂时修复该行为.

正如预期的那样,点击文档本身可以解散框架.然而,一旦再次轻敲文档以激活帧,则与第一图像一样再次发生重叠.
我试过设置documentInteractionControllerRectForPreview无济于事.
- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller
{
return CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height);
}
Run Code Online (Sandbox Code Playgroud)
我不希望在交互控制器启动时隐藏状态栏,我认为可以正确执行此操作,因为Mail应用程序行为正常并且看起来它使用的是同一个类.
为任何想要使用代码的人附加的最小示例项目:https: //hostr.co/PiluL1VSToVt
我通过将 包装UIDocumentInteractionController在 a 中UINavigationController并将应用程序窗口的根视图控制器切换到导航控制器进行演示来解决这个问题。在我的使用中,其他视图控制器没有使用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
Run Code Online (Sandbox Code Playgroud)
虚拟视图控制器允许弹出交互控制器(后退按钮)。