xcode 在 iOS 8 上调整 UIModalPresentationFormSheet 的大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24829461/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Resizing UIModalPresentationFormSheet on iOS 8
提问by Alvaro Franco
I'm trying to resize an UIViewController presented as a modal on iPad using UIModalPresentationFormSheet, and although I got it working on <= iOS 7, I can't on iOS 8
我正在尝试使用 UIModalPresentationFormSheet 在 iPad 上调整显示为模式的 UIViewController 的大小,虽然我在 <= iOS 7 上运行它,但我不能在 iOS 8 上
回答by Micho
For iOS 8 you have to set "preferredContentSize" property, but for iOS 7 and older you have to set the superview.frame property.
对于 iOS 8,您必须设置“preferredContentSize”属性,但对于 iOS 7 及更早版本,您必须设置 superview.frame 属性。
Example code:
示例代码:
UIViewController* modalController = [[UIViewController alloc]init];
modalController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
modalController.modalPresentationStyle = UIModalPresentationFormSheet;
CGPoint frameSize = CGPointMake([[UIScreen mainScreen] bounds].size.width*0.95f, [[UIScreen mainScreen] bounds].size.height*0.95f);
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
// Resizing for iOS 8
modalController.preferredContentSize = CGSizeMake(frameSize.x, frameSize.y);
// Resizing for <= iOS 7
modalController.view.superview.frame = CGRectMake((screenWidth - frameSize.x)/2, (screenHeight - frameSize.y)/2, frameSize.x, frameSize.y);
UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
[vc presentViewController:modalController animated:YES completion:nil];
回答by kevinl
this depends on if you're using UIPopoverPresentationController or UIPresentationController. You can try setting the "preferredContentSize" property to be your new content size (the "contentSizeForViewInPopover" property is deprecated in iOS 8).
这取决于您使用的是 UIPopoverPresentationController 还是 UIPresentationController。您可以尝试将“preferredContentSize”属性设置为新的内容大小(iOS 8 中不推荐使用“contentSizeForViewInPopover”属性)。
回答by bteapot
To resize a UIViewController
's view, when it is already presented with UIModalPresentationFormSheet
modal presentation style and is visible, use for iOS 8+:
要调整 aUIViewController
的视图大小,当它已经以UIModalPresentationFormSheet
模态呈现样式呈现并且可见时,请使用 iOS 8+:
self.preferredContentSize = CGSizeMake(width, height);
[UIView animateWithDuration:0.25 animations:^{
[self.presentationController.containerView setNeedsLayout];
[self.presentationController.containerView layoutIfNeeded];
}];