在iOS 8上调整UIModalPresentationFormSheet的大小

我正在尝试使用UIModalPresentationFormSheet在iPad上调整UIViewController的大小,虽然我已经在< = iOS 7上工作,但我不能在iOS 8

@R_502_5620@

对于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];

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...