在iOS 8上调整UIModalPresentationFormSheet的大小

前端之家收集整理的这篇文章主要介绍了在iOS 8上调整UIModalPresentationFormSheet的大小前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用UIModalPresentationFormSheet在iPad上调整UIViewController的大小,虽然我已经在< = iOS 7上工作,但我不能在iOS 8

解决方法

对于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];
原文链接:/iOS/337305.html

猜你在找的iOS相关文章