Autolayout忽略了iOS7上的UITabBar(条形图下的内容)

时间:2013-09-23 09:34:37

标签: ios7 uitabbar

我在故事板中将UITabBar设置为不透明,但我似乎仍然是半透明的。当我使用setBarStyle设置我的自定义UITabBarController时,只有OpaqueBlack可用。

但问题最少。无论我做什么,我的视图内容都位于标签栏下方,就像它被ayutolayout忽略一样。在故事板上一切都很好。在运行时搞砸了什么?

哦,最重要的是。问题仅发生在iOS7上!

以下是storyboard中的ViewController设置:

enter image description here

这里有问题的内容(UITableView),位于ios7应用程序的UITabBar下。虽然在故事板中看起来很好:

enter image description here

最后是UITableView约束:

enter image description here

4 个答案:

答案 0 :(得分:21)

将其放在viewDidLoad上,解决了问题:

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    [self setEdgesForExtendedLayout:UIRectEdgeNone];
}

答案 1 :(得分:9)

xCode还提供了编程功能:

[self setEdgesForExtendedLayout:UIRectEdgeNone];

通过 Extend Edges 部分为给定的ViewController设置故事板:

enter image description here

只需禁用 Under Top Bars Under bottom Bars 选项。它们默认开启。

答案 2 :(得分:4)

在项目的macros文件中创建这些<projectname>-Prefix.pch,以便它们可以全局运行:

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

然后在[super viewDidLoad]之后将viewDidLoad方法放在每个遇到此问题的viewController方法中:

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) 
{
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
}

答案 3 :(得分:0)

在Swift中UIRectEdgeNone不可用。您可以使用以下代码实现相同的目标:

edgesForExtendedLayout = []
相关问题