简体   繁体   中英

iOS 11 how to pin view to safe area bottom anchor

How do I pin a view's bottom anchor to it's superview's bottom safe area anchor in iOS 11 using interface builder?

I have been able to do it programmatically like so:

if (@available(iOS 11.0, *)) {
    [self.myBottomView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor].active = true;
} else {
    [self.myBottomView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = true;
}

When I go to interface builder I cannot see the bottom safe area anchor:

在此处输入图片说明

On a project created before Xcode 9, storyboards and xibs are not updated automatically to use the safe areas because the existing constraints needs to be changed manually.

You can enable this with an option in the file inspector (in the right panel): 如何启用安全区

Then, the safe area appears like a specific kind a view and you can use it to add your constraints: 添加与安全区域有关的约束

Note that it is possible to use the safe area in a storyboard and have a deployment target lower than iOS 11. I tested in the simulator with iOS 10 and it works as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM