我正在尝试使用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];