Last active
August 29, 2015 14:11
-
-
Save mtsd/c247ec590b0b828bc7ab to your computer and use it in GitHub Desktop.
UIViewController's Workaround
This file contains hidden or 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
| @interface UIViewController (XXX) | |
| /** | |
| iOS8 && iPadの時にmodalPresentationStyleの種類によっては | |
| horizontalSizeClassがUIUserInterfaceSizeClassCompactになるので | |
| TraitCollectionを書き換える。 | |
| 現在判明しているのは | |
| * UIModalPresentationFormSheet | |
| */ | |
| - (void)xxx_overrideTraitCollectionForModalPresentation; | |
| /** | |
| 自動調整対象外のUIScrollViewのcontentInsetsを調整する。 | |
| また、iOS8でcontentOffsetが自動調整されないため、 | |
| それも調整する。 | |
| UIViewController.view | |
| - subview[0] | |
| - subview[1](UIScrollView) <- これ | |
| */ | |
| - (void)xxx_manuallyAdjustsScrollViewInsetsAndOffset:(UIScrollView *)scrollView; | |
| @end | |
| @implementation UIViewController (XXX) | |
| - (void)xxx_overrideTraitCollectionForModalPresentation | |
| { | |
| if (!SYSTEM_VERSION_LESS_THAN(@"8.0")) { | |
| if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { | |
| if (self.parentViewController.modalPresentationStyle == UIModalPresentationFormSheet) { | |
| [self.parentViewController setOverrideTraitCollection: | |
| [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular] | |
| forChildViewController:self]; | |
| } | |
| } | |
| } | |
| } | |
| - (void)xxx_manuallyAdjustsScrollViewInsetsAndOffset:(UIScrollView *)scrollView | |
| { | |
| UIEdgeInsets currentInsets = scrollView.contentInset; | |
| UIEdgeInsets insets = currentInsets; | |
| UIViewController *parent = self; | |
| while (parent.parentViewController.parentViewController) { | |
| parent = parent.parentViewController; | |
| } | |
| insets.top = parent.topLayoutGuide.length; | |
| insets.bottom = parent.bottomLayoutGuide.length; | |
| if (!UIEdgeInsetsEqualToEdgeInsets(currentInsets, insets)) { | |
| scrollView.contentInset = insets; | |
| scrollView.scrollIndicatorInsets = insets; | |
| // iOS8でcontentOffsetが調整されないのを対処 | |
| if (!SYSTEM_VERSION_LESS_THAN(@"8.0")) { | |
| CGFloat d = insets.top + insets.bottom; | |
| [scrollView setContentOffset:CGPointMake(0, -d) animated:NO]; | |
| } | |
| } | |
| } | |
| @end | |
| @implementation UINavigationController (XXX) | |
| /** | |
| http://qiita.com/yusuga_/items/d3097956026553ef9869 | |
| */ | |
| - (BOOL)disablesAutomaticKeyboardDismissal | |
| { | |
| // return NO; | |
| return [self.visibleViewController disablesAutomaticKeyboardDismissal]; | |
| } | |
| @end | |
| #define SYSTEM_VERSION_LESS_THAN(v) \ | |
| ( [[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment