小智 33
对于iOS 8,您必须设置"preferredContentSize"属性,但对于iOS 7及更早版本,您必须设置superview.frame属性.
示例代码:
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];
Run Code Online (Sandbox Code Playgroud)
这取决于你是否使用UIPopoverPresentationController或UIPresentationController.您可以尝试将"preferredContentSize"属性设置为新的内容大小(iOS 8中不推荐使用"contentSizeForViewInPopover"属性).
要调整UIViewController视图的大小,当它已经显示UIModalPresentationFormSheet模式演示样式并且可见时,请使用iOS 8+:
self.preferredContentSize = CGSizeMake(width, height);
[UIView animateWithDuration:0.25 animations:^{
[self.presentationController.containerView setNeedsLayout];
[self.presentationController.containerView layoutIfNeeded];
}];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13877 次 |
| 最近记录: |