gpt4 book ai didi

iphone - PresentModalViewController 可以不全屏吗?

转载 作者:行者123 更新时间:2023-12-03 19:40:30 25 4
gpt4 key购买 nike

我有一个 View Controller ,我正在以模态方式呈现它,如...

UIViewController *myWindow = [[UIViewController alloc] init];
CGRect myFrame = CGRectMake(0.0f, 0.0f, 115.0f, 120.0f);
myWindow.view.frame = myFrame;

[self presentModalViewController:myWindow animated:YES];

有什么方法可以以特定尺寸呈现它而不是全屏吗?

最佳答案

没有“标准”方法可以做到这一点。

我通过使用 UIActionSheet 并将 View Controller 的 View 设置为操作表的 subview ,然后重置操作表的边界来伪造它。这是一个非常奇怪的黑客,我不会推荐它。

sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
sheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;

UIViewController *modalController = [[UIViewController alloc] initWithNibName:@"SomeNib" bundle:nil];

sheet.autoresizesSubviews = NO;
[sheet addSubview:modalController.view];
[sheet showInView:self.view];
[UIView beginAnimations:nil context:nil];
[sheet setBounds:CGRectMake(0, 0, 320, 728)];
[UIView commitAnimations];

这里明显的缺点是不会触发正常的 View Controller 事件(viewWillAppear:viewDidAppear:等)

关于iphone - PresentModalViewController 可以不全屏吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3823727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com