objective-c - 如何在 Objective-C - iOS8 中添加 QLPreviewController 作为 subview

标签 objective-c ios8 qlpreviewcontroller

在以前的 iOS 版本中,我曾经将 QLPreviewController 添加为 subview 。使用我自己的应用程序标题和导航栏非常方便,但在 iOS 8 中它会在标题下方添加一个空白区域。这是它自己的导航栏的空间。

可以看到附件img:screenshot which shows the white bar

我使用这段代码:

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/

相关文章:

ios - 从 UIUserNotificationTypeNone 传递到 UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeBadge | UI用户通知类型声音

ios - 当提供 "get"实现时,@synthesize 会做什么?

xcode - 如何在 Xcode 6.0 中构建并包含第 3 方 C 库

ios - 使用未声明的类型 'QLPreviewControllerDataSource'

ios6 - 在 QLPreviewController 中配置底栏

objective-c - 将工具栏添加到导航 Controller

ios - Apple 方式的 UITableView 事件指示器

swift - SWRevealViewController 和 Swift 的正确使用方法是什么?

xcode - 禁用 UITextField 预测文本

ios - 可以拦截触摸事件的自定义 QLPreviewController 或 UIDocumentInteractionController