gpt4 book ai didi

ios - 在运行时获取 UIModalPresentationFormSheet 的大小

转载 作者:行者123 更新时间:2023-11-29 01:48:34 27 4
gpt4 key购买 nike

我正在为 iPad 制作一个应用程序,它主要是一个带有设置按钮的 UISplitViewController 应用程序,该按钮使用 UIModalPresentationFormSheet 打开设置 View Controller ,如下所示:

SettingsViewController * settingsViewController = [[SettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
settingsViewController.managedObjectContext = self.managedObjectContext;

UINavigationController * settingsNC = [[UINavigationController alloc] initWithRootViewController:settingsViewController];
settingsNC.modalPresentationStyle = UIModalPresentationFormSheet;
settingsNC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:settingsNC animated:YES completion:nil];

settingsViewControllerviewDidLoad 中,我希望能够获取弹出窗口的宽度和高度,我该怎么做?我尝试使用以下内容,但它们都返回整个 iPad 屏幕尺寸..

NSLog(@"x: %f y: %f ",self.view.bounds.size.width,self.view.bounds.size.height);
NSLog(@"x: %f y: %f ",self.view.frame.size.width,self.view.frame.size.height);

// outputs
// x: 1024.000000 y: 748.000000
// x: 1024.000000 y: 748.000000

如有任何帮助,我们将不胜感激!

最佳答案

感谢 Rory,我让这个工作正常,调用以找出 View Controller 的大小只需要在 viewWillAppear 方法中完成。当在 viewDidLoad 中调用时,它会返回父 View 的边界,这就是它返回整个屏幕尺寸的原因 - 我认为这是由于呈现的 View Controller 在 viewDidLoad 之后才在技术上处于事件状态。

-(void)viewWillAppear:(BOOL)animated{
NSLog(@"x: %f y: %f ",self.view.bounds.size.width,self.view.bounds.size.height);
NSLog(@"x: %f y: %f ",self.view.frame.size.width,self.view.frame.size.height);
}

// outputs
// x: 540.000000 y: 576.000000
// x: 540.000000 y: 576.000000

关于ios - 在运行时获取 UIModalPresentationFormSheet 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31662504/

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