我试图将模态视图控制器显示为UIPresentationFormSheet.视图出现,但我似乎无法调整大小.我的XIB具有适当的高度和宽度,但是当我这样调用它时它似乎被覆盖了:
composeTweetController = [[ComposeTweet alloc] initWithNibName:@"ComposeTweet" bundle:nil]; composeTweetController.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:composeTweetController animated:TRUE];
有什么想法吗?我正在使用iPhone SDK 3.2 beta 4
您可以在呈现后调整模态视图的框架:
在iOS 5.1 - 7.1中测试
MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease]; targetController.modalPresentationStyle = UIModalPresentationFormSheet; targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //transition shouldn't matter [self presentViewController:targetController animated:YES completion:nil]; if(floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1){ targetController.view.superview.frame = CGRectInset(targetController.view.superview.frame, 100, 50); }else{ targetController.view.frame = CGRectInset(targetController.view.frame, 100, 50); targetController.view.superview.backgroundColor = [UIColor clearColor]; }
这是一个适用于iOS7以及iOS5和iOS6的方法:(弧形)
-(void)presentController:(UIViewController*)controller fromRootController:(UIViewController*)rootController withSize:(CGSize)size { UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:controller]; nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical; nav.modalPresentationStyle = UIModalPresentationFormSheet; [rootController presentModalViewController:nav animated:YES]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { nav.view.superview.backgroundColor = [UIColor clearColor]; nav.view.bounds = CGRectMake(0, 0, size.width, size.height); } else { nav.view.superview.bounds = CGRectMake(0, 0, size.width, size.height); } }
composeTweetController = [[ComposeTweet alloc] initWithNibName:@"ComposeTweet" bundle:nil]; composeTweetController.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:composeTweetController animated:TRUE]; //if you want to change its size but the view will remain centerd on the screen in both portrait and landscape then: composeTweetViewController.view.superview.bounds = CGRectMake(0, 0, 320, 480); //or if you want to change it's position also, then: composeTweetViewController.view.superview.frame = CGRectMake(0, 0, 320, 480);
从iOS7开始,你可以做到
composeTweetController.preferredContentSize = CGSizeMake(380.0, 550.0);