在以前的 iOS 版本中,我曾经将 QLPreviewController 添加为 subview 。使用我自己的应用程序标题和导航栏非常方便,但在 iOS 8 中它会在标题下方添加一个空白区域。这是它自己的导航栏的空间。
可以看到附件img:
我使用这段代码:
QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.dataSource = self;
previewController.delegate = self;
previewController.currentPreviewItemIndex = 0;
previewController.view.frame = CGRectMake(0, 0, self.containerView.frame.size.width, self.containerView.frame.size.height);
[self addChildViewController:previewController];
[previewController didMoveToParentViewController:self];
[self.containerView addSubview:previewController.view];
如何保持 iOS7 的功能?我只想隐藏qlpreviewcontroller导航栏
谢谢
最佳答案
我正在解决完全相同的问题。到目前为止,我找到的唯一解决方案如下:
// qlController.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));//self.view.bounds;
// qlController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addChildViewController:qlController];
[self.view addSubview:qlController.view];
NSDictionary *bindings = @{@"qlPreviewController": qlController.view};
qlController.view.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[qlPreviewController]|" options:0 metrics:nil views:bindings]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[qlPreviewController]|" options:0 metrics:nil views:bindings]];
[qlController didMoveToParentViewController:self];
注释行是遗留代码,在 iOs7
上完美运行。主要思想是停止使用 spring 和 struts 并开始使用自动布局。结果看起来不错,但旋转仍然存在一些问题。
效果不错: Iphone 4s/5/6/6+ iOs7人像+风景,iOS8人像 iPad 所有机型 iOs7,8 竖屏+横屏
效果不好: Iphone 4s/5/6/6+ iOs8 横向:导航栏和内容之间有一些间距。我认为这是 Apple 的 QLPreviewController 而不是我的代码的问题。
关于objective-c - 如何在 Objective-C - iOS8 中添加 QLPreviewController 作为 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26753191/