Issue with portrait display after playing landscap

2019-08-09 17:46发布

问题:

I have an iPhone app that displays files to the user (videos, pdf files and documents). When you click on a file thumbnail in my FileViewController I call UIDocumentInteractionController to present the file to the user. All app screens are locked to portrait orientation apart from the document controller, that can be rotated to view landscape. This has all worked fine in previous releases, but it has suddenly changed and broken, I presume when iOS 8 was released.

Now, if I play a video and rotate it to landscape and hit done, the video is removed from the screen and the FileViewController nib that called the document the view is cut off half way down the screen.

I've done some testing and have printed out the view bounds width and height. Testing on an iPhone 4S, when I first load the FileViewController the width and height is 320 x 480, correct.

When I play a video in landscape mode and hit done, the underlaying view is automatically rotated back to portrait as landscape isn't support in this view, but when printing out the screen bounds the width is 480 and height 320. It still thinks the app is in landscape even though it's been moved back to portrait. The screen itself is the right way round, just cut off after 320 pixels!

I've been trying to manipulate the orientation of alsorts of controls but I can't see what's even generating the issue, let alone fixing it.

This is how I have implemented by orientations:

The App has been set up to support ALL orientations.

I have subclasses the tab bar controller to specify the following:

- (BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

Within FileViewController I call the following code:

- (void) Show_File:(File *)file 
{
    NSURL *targetURL = [NSURL fileURLWithPath:filePath];

    UIDocumentInteractionController *document = [UIDocumentInteractionController interactionControllerWithURL: targetURL];
    document.delegate = self;

    [document presentPreviewAnimated: YES];
}

- (UIViewController *)documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller
{
    AppDelegate *theDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];

    return theDelegate.fileNavController.childViewControllerForStatusBarHidden;
}

Any ideas? I've search around but I can't find anyone having this particular issue. Thanks.

回答1:

Just for anyone else experiencing this issue, I raised a support ticket with Apple and apparently it is an iOS bug....

"This is a bug QLPreviewController (which is used by UIDocumentInteractionController to display previews)"

I have a work around which is working ok for now. In my subclass of UITabBarController I've incldued this code:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

     if (self.transitionCoordinator && self.presentedViewController.presentationController {
        self.view.frame = self.presentedViewController.presentationController.containerView.bounds;
     }
}