当前位置:  开发笔记 > IOS > 正文

如何调整UIModalPresentationFormSheet的大小?

如何解决《如何调整UIModalPresentationFormSheet的大小?》经验,为你挑选了4个好方法。

我试图将模态视图控制器显示为UIPresentationFormSheet.视图出现,但我似乎无法调整大小.我的XIB具有适当的高度和宽度,但是当我这样调用它时它似乎被覆盖了:

composeTweetController = [[ComposeTweet alloc] initWithNibName:@"ComposeTweet" bundle:nil];
composeTweetController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:composeTweetController animated:TRUE];

有什么想法吗?我正在使用iPhone SDK 3.2 beta 4



1> Brody Robert..:

您可以在呈现后调整模态视图的框架:

在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];
}


它也可以在iPad上使用,但是......如果我旋转设备,视图不会居中
@MauroDelrio为了使其在横向上正常工作,您需要翻转中心坐标.例如:CGPoint center = self.view.center; targetController.view.superview.center = {isPortrait}?center:CGPointMake(center.y,center.x);
小心这种方法,由于缩放,它会导致视图控制器视图中出现一些失真.
需要IOS7的解决方案

2> psy..:

这是一个适用于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);
    }
}



3> Skullhouseap..:

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);



4> 小智..:

从iOS7开始,你可以做到

composeTweetController.preferredContentSize = CGSizeMake(380.0, 550.0);

推荐阅读
农大军乐团_697
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有