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
答案 0 :(得分:0)
我通过将UIDocumentInteractionController
包装在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
虚拟视图控制器允许弹出交互控制器(后退按钮)。
答案 1 :(得分:0)
找到新的解决方案。
在info.plist文件中为iOS 7添加: UIViewControllerBasedStatusBarAppearance(查看基于控制器的状态栏外观)= NO
答案 2 :(得分:0)
这些解决方案对我不起作用。我找到的唯一解决方案是在委托请求呈现视图控制器之后强制状态栏在下一个runloop上可见(需要UIViewControllerBasedStatusBarAppearance设置为NO):
- (UIViewController *) documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *) controller {
// hack to keep status bar visible
[[NSOperationQueue mainQueue] addOperationWithBlock:
^{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}];
return self.viewController;
}
答案 3 :(得分:0)
尝试使用以下代码对我有用:
- (void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}