在运行时

时间:2015-07-27 20:19:44

标签: ios objective-c ipad cocoa-touch

我正在为iPad制作应用程序,它主要是带有设置按钮的UISplitViewController应用程序,可使用UIModalPresentationFormSheet打开设置视图控制器,如下所示:

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

viewDidLoad的{​​{1}}范围内,我希望能够获得弹出窗口的宽度和高度,我该怎么做?我试过使用以下内容,但它们都返回整个iPad屏幕尺寸..

settingsViewController

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

感谢Rory我已经正确地工作了,只需要在viewWillAppear方法中完成查找视图控制器大小的调用。在viewDidLoad中调用时,它返回superview的边界,这就是它返回整个屏幕尺寸的原因 - 我认为这是因为在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 
相关问题