6

是否可以查询(以编程方式,在运行时)导航栏和/或工具栏的高度/厚度在旋转后是多少?

也就是说,在为特定子视图构建框架时,我想将其框架设置为相对于导​​航栏和工具栏之间的可用空间。为了使其平滑,最好在shouldAutorotateToInterfaceOrientation:而不是中执行此操作didRotateFromInterfaceOrientation:,但是诸如方向设备self.navigationController.toolbar.frame.size.height之间的值是不同的。

我想根据工具栏的厚度来计算我的新子视图框架并且我想在没有硬编码值(例如 32pt、44pt 等)的情况下做到这一点。

有什么想法吗?

4

2 回答 2

1

willAnimateRotationToInterfaceOrientation:duration:您可以在方法中更改视图框架。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];

    NSLog(@"%@", NSStringFromCGRect(self.navigationController.navigationBar.frame));
}

有关更多信息,请查看 Apple 提供的文档。

于 2011-08-20T05:56:07.167 回答
1

您应该调整所有框架的大小willAnimateRotationToInterfaceOrientation:duration:

AFAIK 没有办法预测你的 UIViews 的大小,直到你到达didRotateFromInterfaceOrientation:

一种方法是在代码中调整所有框架的大小,包括工具栏。这样您就可以完全控制 UI 元素的大小。

于 2011-10-12T07:37:17.357 回答