使用iPhone X的自动调整大小蒙版迁移项目 [英] Migrating a project using autoresizing masks for iPhone X

查看:156
本文介绍了使用iPhone X的自动调整大小蒙版迁移项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一些旧项目仍在使用自动调整大小"蒙版,并且在iOS 11和iPhone X之前一切正常.通过引入安全区域布局指南,支持iPhone X的最佳解决方案是什么?

We have some legacy projects that are still using Autoresizing masks, and everything was working fine until iOS 11 and iPhone X. With the introduction of safe area layout guides, what's the best solution to support iPhone X?

  1. 我们可以将所有具有自动调整大小的掩码的界面转换为使用自动布局.考虑到视图是动态添加和调整的,这似乎是一项巨大的工作.

  1. We can convert all interfaces with autoresizing masks to use auto-layouts. This appears to be a significant effort, considering views are being dynamically added and adjusted.

我们继续使用自动调整大小的蒙版,但会调整界面以增加iPhone X和iOS 11的插入页边距.

We keep using autoresizing masks but adjust the interfaces to add inset margins for iPhone X and iOS 11.

推荐答案

第三个选择是在需要的地方使用自动布局,而将应用程序的其余部分保留为自动调整大小.从XCode 8开始,您可以混合使用自动调整大小和自动布局.对于xib或情节提要中的每个视图,您可以选择设置自动调整大小的蒙版或自动布局约束.在视图上使用一种规则会禁用该视图的另一种规则.但是您可以在另一种视图上使用另一种.该链接包含更多信息: http://www.thomashanning. com/xcode-8-mixing-auto-autoresizing-masks/

A third option would be to use autolayout where you need to and leave the rest of the app with autoresizing. Since XCode 8, you may mix autoresizing and autolayout. For each view in the xib or storyboard, you may choose to set an autoresizing mask or autolayout constraints. Using one kind of rules on a view disables the other kind for that view. But you may use the other kind on another view. This link has some more information : http://www.thomashanning.com/xcode-8-mixing-auto-autoresizing-masks/

如果您选择仅继续使用自动调整大小的蒙版,则以下帮助方法可能会帮助您正确布置视图.

If you choose to keep using only autoresizing masks, the helper methods below may help you to layout your views correctly.

statusBarHeight 为您提供设备状态栏的高度. safeAreaBottomMargin 为您提供iPhoneX主页按钮指示器的左下角空白.

statusBarHeight gives you the height of the status bar for the device. safeAreaBottomMargin gives you the bottom margin left for iPhoneX's home button indicator.

- (CGFloat) statusBarHeight {
    return UIApplication.sharedApplication.statusBarFrame.size.height;
}

- (CGFloat) safeAreaBottomMargin {
    if (@available(iOS 11.0, *)) {
        UIWindow *window = UIApplication.sharedApplication.windows.firstObject;
        return window.safeAreaLayoutGuide.owningView.frame.size.height - window.safeAreaLayoutGuide.layoutFrame.size.height - window.safeAreaLayoutGuide.layoutFrame.origin.y;
    } else {
        return 0;
    }
}

这篇关于使用iPhone X的自动调整大小蒙版迁移项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆