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);
}
我不希望在交互控制器出现时隐藏状态栏,我认为这是可能做到正确的,因为邮件应用程序行为正确,而且看起来它正在使用相同的类。
附有最小示例项目供任何想要尝试代码的人使用: https://hostr.co/PiluL1VSToVt