QLPreviewController delegate method doesn't ge

2019-06-10 15:21发布

Here is my code. This may sound like redundant question but my scenario is different as I am not adding QLPreviewController as a subview but present as a controller.

After downloading from dropbox, I present it like-

    self.pdfViewController = [[QLPreviewController alloc] init];
    self.pdfViewController.delegate = self;
    self.pdfViewController.dataSource = self;

    [self presentViewController:self.pdfViewController animated:YES completion:nil];

and I also have QLPreviewControllerDataSource, QLPreviewControllerDelegate listed as the protocol. Besides, it is working if being run in earlier than iOS 10.0.

Please help me.

1条回答
ゆ 、 Hurt°
2楼-- · 2019-06-10 15:48

It looks like iOS 10 has changed the way that QLPreviewController is presented. On iOS 9 when I preview an image by presenting the QLPreviewController modally I see a nice zoom effect and the initial state of the preview is with a black background and the navigation and toolbar hidden. I can tap the image to make the bars visible (which changes the background to white). Tapping again toggles the state.

On iOS 10 the same code results in the white background view appearing and the zoom animation being incorrect (it seems to appear from off the bottom of the screen).

I found that implementing this practically undocumented new data source method for iOS 10 fixed the issue:

- (UIView* _Nullable)previewController:(QLPreviewController *)controller
          transitionViewForPreviewItem:(id <QLPreviewItem>)item
{
    return [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:MIDPhotoImageRowIndex_Image inSection:MIDPhotoSectionIndex_Image]];
}

The view I return is the same view that previewController:frameForPreviewItem:inSourceView: is using as the reference for the original content's frame (i.e. the image view in my table cell).

The documentation for this delegate method at the time of writing just says "No overview available".

Implementing that method did mean that the previewController:frameForPreviewItem:inSourceView: is now called on iOS 10. I just wish there was a way to default to the original black background without navigation bars.

查看更多
登录 后发表回答