我们有一个UISplitViewController,在条件X下,我们需要从Master视图的UIBarButtonItem之一显示一个UIPopover。
据说,为了使框架/布局正确,我们从主视图控制器的viewDidLoad事件中执行此代码。不知何故,第一次显示UISplitViewController时,Master的帧是1024x724,而我们期望它是320x724。因此,对[UIPopover presentFromBarButtonItem:]的调用使用了错误的引用,因为它是一个正确的BarButtonItem,弹出窗口一直显示在屏幕右侧(大约x = 980px)
如果我们延迟显示一秒钟(通过定时器/延迟, sooo dirty ),那么一切都很好。
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CGRect masterViewFrame = self.view.frame;
NSLog(@"Master View Frame: %@", NSStringFromCGRect(masterViewFrame));
if (someCondition) {
[self showPopover:self.theBarButton];
}
}
此处的NSLog显示1024x724 @ 0x0
思想?
答案 0 :(得分:0)
您可以这样做:
//Check if you really are in a UISplitViewController
CGRect frame = self.view.frame; //this is the default value
if(self.splitViewController)
{
//you are trying to access the frame of this VC's view via the splitViewController
//this should return the correct size
frame = [[[self.splitViewController.viewControllers objectAtIndex:0] view] frame];
}