0
iPad上でフォームとしてUINavigationController + UICollectionViewControllerを提示していて、横向きと縦向きの明示的なサイズを希望します。何らかの理由で私のアプローチでは、回転後に一貫した結果を得ることができません。それは両方の向きで、そして風景から肖像画に回転するときの最初のプレゼンテーションのために働くようです。肖像画から風景に回転すると、それが壊れます。回転時のIPadモーダルフォームサイズの問題
ご注意私はiOS 10+をターゲットにしており、利用可能な既存のアドバイスの多くはもう適用されません。
@implementation FormCVC
- (void)viewDidLoad {
...
[self setupFrame];
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator animateAlongsideTransition:^(id _Nonnull context) {
[self setupFrame];
} completion:^(id _Nonnull context) {
UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)self.collectionView.collectionViewLayout;
[layout invalidateLayout];
}];
}
- (void)setupFrame {
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
NSLog(@"Portrait");
self.preferredContentSize = CGSizeMake(VIEW_PORTRAIT_WIDTH, VIEW_PORTRAIT_HEIGHT);
} else {
NSLog(@"Landscape");
self.preferredContentSize = CGSizeMake(VIEW_LANDSCAPE_WIDTH, VIEW_LANDSCAPE_HEIGHT);
}
[self.navigationController.presentationController.containerView setNeedsLayout];
[self.navigationController.presentationController.containerView layoutIfNeeded];
}