草庐IT

ios - UISplitViewController Master View 在 vi​​ewDidAppear 中的帧大小

coder 2024-01-13 原文

我们有一个 UISplitViewController,在条件 X 下,我们需要从主视图的 UIBarButtonItem 之一显示一个 UIPopover。

据推测,为了使框架/布局正确,我们从主视图 Controller 的 viewDidLoad 事件中执行此代码。不知何故,第一次显示 UISplitViewController 时,Master 的框架是 1024x724,而我们期望它是 320x724。结果,对 [UIPopover presentFromBarButtonItem:] 的调用使用了错误的引用,因为它是一个正确的 BarButtonItem,弹出窗口一直出现在屏幕右侧(大约 x = 980 像素)

如果我们将显示延迟一秒钟(通过定时器/延迟,太脏了),那么一切都很好。

- (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

想法?

最佳答案

你可以这样做:

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

关于ios - UISplitViewController Master View 在 vi​​ewDidAppear 中的帧大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9489286/

有关ios - UISplitViewController Master View 在 vi​​ewDidAppear 中的帧大小的更多相关文章

随机推荐