iOS 9:以编程方式进行安全区域布局,并删除视图中的侧边空间
如何在我的应用程序中为iPhone 5S和iOS 9.3.5添加安全区域布局。 我的代码是这样的iOS 9:以编程方式进行安全区域布局,并删除视图中的侧边空间,ios,objective-c,iphone,xcode,ios9.3,Ios,Objective C,Iphone,Xcode,Ios9.3,如何在我的应用程序中为iPhone 5S和iOS 9.3.5添加安全区域布局。 我的代码是这样的 if (@available(iOS 11, *)) { loginView = [[LoginView alloc] initWithFrame:self.view.safeAreaLayoutGuide.layoutFrame]; [self.view addSubview:loginView]; loginView.translatesA
if (@available(iOS 11, *))
{
loginView = [[LoginView alloc] initWithFrame:self.view.safeAreaLayoutGuide.layoutFrame];
[self.view addSubview:loginView];
loginView.translatesAutoresizingMaskIntoConstraints = NO;
UILayoutGuide * guide = self.view.safeAreaLayoutGuide;
[loginView.leadingAnchor constraintEqualToAnchor:guide.leadingAnchor].active = YES;
[loginView.trailingAnchor constraintEqualToAnchor:guide.trailingAnchor].active = YES;
[loginView.topAnchor constraintEqualToAnchor:guide.topAnchor].active = YES;
[loginView.bottomAnchor constraintEqualToAnchor:guide.bottomAnchor].active = YES;
}
else
{
loginView = [[LoginView alloc] initWithFrame:self.view.layoutMarginsGuide.layoutFrame];
[self.view addSubview:loginView];
loginView.translatesAutoresizingMaskIntoConstraints = NO;
UILayoutGuide *margins = self.view.layoutMarginsGuide;
[viloginViewew.leadingAnchor constraintEqualToAnchor:margins.leadingAnchor].active = YES;
[loginView.trailingAnchor constraintEqualToAnchor:margins.trailingAnchor].active = YES;
[loginView.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor].active = YES;
[loginView.bottomAnchor constraintEqualToAnchor:self.bottomLayoutGuide.topAnchor].active = YES;
}
我试图在我的设备中运行,但安全区域布局显示左右两侧有一些空间。我想删除该空间,使其显示全宽
而且我从layoutMarginsGuide中得到的高度太长,所以它被隐藏在视线之外。如何获得正确的布局边缘高度指南
我是否实现了错误的代码?我该怎么办?iPhone 5s对我来说很管用。它覆盖了所有的空间。将其用于11以下的iOS
[self.view addConstraints:@[
[NSLayoutConstraint constraintWithItem:loginView
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.bottomLayoutGuide
attribute:NSLayoutAttributeBottom
multiplier:1
constant:0],
[NSLayoutConstraint constraintWithItem:loginView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.bottomLayoutGuide
attribute:NSLayoutAttributeTop
multiplier:1
constant:0],
[NSLayoutConstraint constraintWithItem:loginView
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeading
multiplier:1
constant:0],
[NSLayoutConstraint constraintWithItem:loginView
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeTrailing
multiplier:1
constant:0]
]]
只需删除self.view.layoutMarginsGuide to self.view我收到这样的警告:“无法同时满足约束。下面列表中可能至少有一个约束是您不想要的。”看起来视图确实满了,没有左、右空间,但也没有顶部空间。我的俯视图是落后时间,电池状态现在。我希望我的顶视图不在落后时间,电池状态。将顶部常量设置为20,第二个约束,状态栏将可见