在iOS7中,状态栏位于视图上方,没有情节提要
我用ios7sdk创建了我的第一个应用程序,一个没有故事板的“空应用程序”。 状态栏始终位于所有其他视图上方。 因此,我添加了以下代码:在iOS7中,状态栏位于视图上方,没有情节提要,ios,ios7,Ios,Ios7,我用ios7sdk创建了我的第一个应用程序,一个没有故事板的“空应用程序”。 状态栏始终位于所有其他视图上方。 因此,我添加了以下代码: if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) self.edgesForExtendedLayout = UIRectEdgeNone; 但这并没有改变什么。我的完整代码: - (void)viewDidLoad { [super viewDidLoad];
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
但这并没有改变什么。我的完整代码:
- (void)viewDidLoad
{
[super viewDidLoad];
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(30, 0, 200, 300)];
[v setBackgroundColor:[UIColor greenColor]];
[self.view addSubview:v];
}
edgesForExtendedLayout仅适用于存在UI容器视图控制器(例如UINavigationController)的情况。为了避免重叠,应该使用-topLayoutGuide(它还存在一个底部布局指南)。我已经制作了一个使用容器视图作为vc主视图的子视图的布局集
//This should be added before the layout of the view
- (void) adaptToTopLayoutGuide {
//Check if we can get the top layoutguide
if (![self respondsToSelector:@selector(topLayoutGuide)]) {
return;
}
//tankView is a contaner view
NSArray * array = [self.tankView referencingConstraintsInSuperviews]; //<--For this method get the Autolayout Demistified Book Sample made by Erica Sadun
[self.view removeConstraints:array];
NSArray * constraintsVertical = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[topLayoutGuide]-0-[tankView]|" options:0 metrics:nil views:@{@"tankView": self.tankView, @"topLayoutGuide":self.topLayoutGuide}];
[self.view addConstraints:constraintsVertical];
NSArray * constraintsHorizontal = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[tankView]|" options:0 metrics:nil views:@{@"tankView": self.tankView}];
[self.view addConstraints:constraintsHorizontal];
}
//这应该添加到视图布局之前
-(无效)适用于布局指南{
//看看我们是否能得到最上面的布局指南
如果(![self respondsToSelector:@selector(topLayoutGuide)]){
返回;
}
//tankView是一个contaner视图
NSArray*array=[self.tankView referencenconstraintsinsuperViews];//是否隐藏(或删除)状态栏或只是让您的视图正确定位在状态栏下方?状态栏下方的视图,如iOS6上的视图。您的问题是否由???回答?因此,我必须使用情节提要?一点也不。该相关/重复问题中只有一个答案仅适用于情节提要。