【问题标题】:Determining the usable area of an UIView确定 UIView 的可用区域
【发布时间】:2010-10-12 04:33:02
【问题描述】:

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

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

和视图

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

窗口恢复为 320x480,视图恢复为 320x460(我假设 20 像素的差异是顶部的状态栏)。

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

【问题讨论】:

    标签: iphone objective-c cocoa


    【解决方案1】:

    我假设您正在以编程方式创建视图并尝试在选项卡控制器中动态布局。 使用 OS 上的 UIViewAutoresizing 和信任来为您完成。

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

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

    【讨论】:

    • 谢谢,这正是我想要的。我很感激。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-09
    • 1970-01-01
    • 2012-07-14
    相关资源
    最近更新 更多