简体   繁体   English

如何将兼容的现有应用程序制作到iPhone X.

[英]How to make compatible existing app to iPhone X

We have an application with 6 to 8 screens which was developed by Swift 3.2 version. 我们有一个6到8个屏幕的应用程序,由Swift 3.2版本开发。 And I am using Size classes (Auto Resize),not using autolayouts for all devices its working fine. 我正在使用大小类(自动调整大小),不使用自动布局来为所有设备工作正常。

But, Now, We want to make it compatible with iPhone X device. 但是,现在,我们想让它与iPhone X设备兼容。

While we testing app in iPhone X, there are lot of issues on top, bottom views and even centre of the screen in Subviews. 当我们在iPhone X中测试应用时,在顶视图,底视图甚至是子视图中的屏幕中心都存在很多问题。

I have seen, few forums which were told, "Use adaptive Sage Guide" in Story board files of UI, and issue would be solved. 我看到,在UI的Story板文件中,很少有论坛被告知“使用自适应Sage指南”,问题就解决了。 But, Event I tried that, still lot of gaps and issues coming bottom and top while testing app with iPhone X. 但是,事件我尝试过,在使用iPhone X测试应用程序时仍然存在很多差距和问题。

So, how to make compatible with iPhone X with my existing code, do I need to change everything in programmatically for below iPhone X and iPhone X, or is there anything there? 那么,如何使用我现有的代码与iPhone X兼容,我是否需要以编程方式更改below iPhone X and iPhone X,所有内容below iPhone X and iPhone X,或者有什么吗?

Can anyone suggest me, how to proceed for this. 任何人都可以建议我,如何继续这样做。

Note : We are using Xcode 9.2 注意:我们使用的是Xcode 9.2

在此输入图像描述

在此输入图像描述

在此输入图像描述

It's not just an iPhone X thing, it's also an iOS 11 thing. 它不仅仅是iPhone X的东西,它也是iOS 11的东西。 iOS 11 introduces a brand new inset adjustment API that deprecates most (maybe all?) of what preceded it. iOS 11引入了一个全新的插入式调整API,它在它之前的大部分内容(可能是全部?)中弃用。 And with iPhone X's physical design, even more attention to safe areas must be made. 使用iPhone X的物理设计,必须更加注重安全区域。

So get used to writing these: 所以习惯写这些:

if #available(iOS 11.0, *) {

    // new iOS 11 syntax
    someView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true

} else {

    // pre-iOS 11 syntax
    someView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor).isActive = true

}

the safeAreaLayoutGuide is now a property of the view itself and it's more intuitive, IMO. safeAreaLayoutGuide现在是视图本身的属性,它更直观,IMO。 More examples of the new API syntax: 更多新API语法的示例:

someView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
someView.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor).isActive = true
someView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true

And if you're interested in getting inset values: 如果您对获取插入值感兴趣:

if #available(iOS 11.0, *) {
    someViewAnchor.constant = view.safeAreaInsets.bottom
} else {
    someViewAnchor.constant = bottomLayoutGuide.length
}

If you're using storyboards, you should open them now, go the file inspector, then select the Use Safe Area Layout guide checkbox – that will switch you over to the new system. 如果您正在使用故事板,则应立即打开它们,转到文件检查器,然后选中“使用安全区域布局”指南复选框 - 这将切换到新系统。 https://www.hackingwithswift.com/articles/12/how-to-update-your-app-design-for-iphone-x https://www.hackingwithswift.com/articles/12/how-to-update-your-app-design-for-iphone-x

After adding Safe Area Guides you need to do little changes in constraints attribute like those constraints which are using superview.top and superview.bottom of the screen after applying the Safe Guide the superview need to change to the Safe Area like in the picture below 添加Safe Area Guides您需要对约束属性进行少量更改,例如在应用Safe Guide后使用屏幕的superview.top和superview.bottom时, superview需要更改为Safe Area ,如下图所示

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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