Last active
August 29, 2015 14:27
-
-
Save stevenchan/2e6d61eb295bd209896b to your computer and use it in GitHub Desktop.
Detecting if a view controller is presented in a popover with UITraitCollection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)prepareForPopoverPresentation:(UIPopoverPresentationController *)popover | |
{ | |
if (!self.adaptivePresentationStyleAsked) { | |
popover.overrideTraitCollection = [popover.presentingViewController.traitCollection copy]; | |
} | |
} | |
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)popover | |
traitCollection:(UITraitCollection *)traitCollection | |
{ | |
self.adaptivePresentationStyleAsked = YES; | |
popover.overrideTraitCollection = [traitCollection copy]; | |
if (traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact || | |
traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact) { | |
return UIModalPresentationOverFullScreen; | |
} else { | |
return UIModalPresentationPopover; | |
} | |
} | |
- (void)presentationController:(UIPresentationController *)popover | |
willPresentWithAdaptiveStyle:(UIModalPresentationStyle)style | |
transitionCoordinator:(id<UIViewControllerTransitionCoordinator>)transitionCoordinator | |
{ | |
[popover.presentedViewController willTransitionToTraitCollection:popover.overrideTraitCollection | |
withTransitionCoordinator:transitionCoordinator]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection | |
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator | |
{ | |
[super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator]; | |
if (newCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact || | |
newCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact) { | |
// full screen | |
} else { | |
// popover | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment