【问题标题】:UISplitViewController Master View frame size in viewDidAppearUISplitViewController viewDidAppear 中的主视图帧大小
【发布时间】:2012-02-28 20:34:21
【问题描述】:

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

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

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

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

想法?

【问题讨论】:

  • 你是放在-viewDidLoad之前还是之后?你能把它放在viewWillAppearviewDidAppear吗?
  • 在原始问题中添加了代码示例。我本质上是在 viewDidAppear 结束时拨打电话
  • 你是如何创建拆分视图的?
  • 整个事情都在故事板中

标签: ios ipad uisplitviewcontroller


【解决方案1】:

你可以这样做:

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

【讨论】:

    猜你喜欢
    • 2016-07-07
    • 2014-09-01
    • 2013-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多