确定UIView的可用区域

时间:2009-03-09 13:19:34

标签: iphone objective-c cocoa

我是一个iPhone开发新手,我遇到了一个问题,弄清楚当UIViews的控制器是UITabController的一部分时,我能够使用多少UIView。我正在将窗口初始化为

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

和视图

myView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

窗口返回为320x480,视图为320x460(20像素差异,我认为,状态栏位于顶部)。

但是,视图是UITabController的一部分,我不知道如何计算在考虑该标签栏时可用的空间量。有什么想法吗?

1 个答案:

答案 0 :(得分:3)

我假设您正在以编程方式创建视图,并尝试在选项卡控制器中动态布局。 使用UIViewAutoresizing并信任操作系统为您完成。

我遇到了类似的麻烦,直到我花时间了解如何使用Flexible属性锁定某些位置的元素。当您使用选项卡控制器切换所选视图时,操作系统将调整视图大小以自动适应。

UIViewAutoresizingFlexibleTopMargin - Locks the location of an object with regards to the bottom.
UIViewAutoresizingFlexibleBottomMargin - Locks with regards to the top.
UIViewAutoresizingFlexibleWidth - Keeps the object the same distance from the left and right edges.
UIViewAutoresizingFlexibleHeight - Keeps the object the same distance from the top and bottom edges.

顶部和底部一开始似乎倒退,直到您意识到定义允许更改的边距。

要以编程方式配置,需要设置视图的autoresizingMask:

[myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin];
相关问题