How to add QLPreviewController as Subview in C object - iOS8

In previous versions of iOS, I added QLPreviewController as a subtitle. It's very handy for using my own app titles and navbar, but in iOS 8 it adds a space just below the title. This is the space for your own navigation bar.

You can see the attached img file: screenshot which shows the white bar

I am using this code:

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];

      

How can I use iOS7 feature? I only want to hide navbar qlpreviewcontroller

thank

+3


source to share


1 answer


I am solving the EXACT same problem. The only solution I have found so far is this:

//    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];

      

The commented lines are legacy code that worked great for iOs7

. The basic idea is to ditch using spring and layouts and start using auto-layout. The results look good enough, but there are still some cornering issues.



Works well: Iphone 4s / 5/6/6 + iOS7 portrait + landscape, iOs8 portrait iPad all iOs7,8 models portrait + landscape

Poor performance: Iphone 4s / 5/6/6 + iOs8 landscape: has some spacing between navBar and content. I think this is a problem with Apple's QLPreviewController, not my code.

0


source







All Articles