Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save douglashill/e1e1d6fd3d59a3c59295 to your computer and use it in GitHub Desktop.
Save douglashill/e1e1d6fd3d59a3c59295 to your computer and use it in GitHub Desktop.
// This is more hacky than it should be!
- (UIModalPresentationStyle)pspdf_currentPresentationStyle {
UIViewController *vc = self.presentedViewController.presentingViewController;
if ([self respondsToSelector:@selector(adaptivePresentationStyleForTraitCollection:)]) {
UIModalPresentationStyle const style = [self adaptivePresentationStyleForTraitCollection:vc.traitCollection];
return (style == UIModalPresentationNone) ? self.presentationStyle : style;
}
// Before iOS 8.3 we have to fall back on assuming adaptivity is only possible for horizontally compact environments.
// UIKit seems to do the same: UIModalPresentationPopover results in popover on iPhone 6 Plus in landscape.
if (vc.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
UIModalPresentationStyle style = self.adaptivePresentationStyle;
if (style != UIModalPresentationNone) {
return style;
}
}
return self.presentationStyle;
}
- (BOOL)pspdf_isPopover {
return self.pspdf_currentPresentationStyle == UIModalPresentationPopover;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment