简体   繁体   English

如何为Apps支持iPhone X分辨率或屏幕尺寸?

[英]How to support iPhone X Resolution or screen size for Apps?

After 2017 keynote today and iPhone X launch i am equally worried as excited about new iphone. 在2017年主题演讲和iPhone X发布之后,我同样担心新iphone的兴奋。 This question is more about user interface, design guidelines or approach on interface designs than technical issues. 这个问题更多是关于用户界面,设计指南或界面设计方法而不是技术问题。

My question is how to support the 1125px × 2436px (375pt × 812pt @3x) resolution ? 我的问题是如何支持1125px×2436px(375pt×812pt @ 3x)分辨率?

As shown in this image by apple on its Human Interface Guidelines for iPhoneX , It is told here that it will support 3x image extension. 如苹果公司针对iPhoneX的人机界面指南所示 ,这里的图片显示它将支持3倍图像扩展。 But there are 185 points extra at the top as well as considering 414 * 736 points for iphone 7 plus resolution it is 414 - 375 = 39 points less in width. 但是在顶部还有185分额外,考虑到414 * 736分,iphone 7加分辨率为414 - 375 =宽度减少了39分。

You can check out resolution comparison here:- https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions . 您可以在此处查看分辨率比较:​​ - https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

How can we possibly design our app for this new design resolution? 我们怎么可能为这个新的设计分辨率设计我们的应用程序?

Some problem scenarios: 一些问题场景:

How to support: 如何支持:

  1. horizontal imageviews scaling the whole width of the device and a fixed height. 水平图像视图缩放设备的整个宽度和固定高度。
  2. ImageViews scaling whole width and height (like full page product images in ecommerce apps). ImageViews缩放整个宽度和高度(如电子商务应用程序中的整页产品图像)。
  3. There is extra 185 points height which will show a lot of blank space if i show a limited content on the page. 还有额外的185点高度,如果我在页面上显示有限的内容,将显示很多空白。 for example, How do i design a view that is 400 pixel in height and scaling whole width. 例如,如何设计高度为400像素并缩放整个宽度的视图。 Should i keep it top aligned centre aligned vertically ? 我应该保持顶部对齐的中心垂直对齐吗?

I think 185 points is a lot of real estate for height. 我认为185分是很多高空的房地产。 We need to reconsider a lot of designs and screens. 我们需要重新考虑很多设计和屏幕。 How can we design and address these scenarios? 我们如何设计和解决这些情况? i hope my question is clear enough now. 我希望我的问题现在已经足够清楚了。

My Personal opinion:- No matter how tough or messy it is, End user experience is going to be better and bigger when we get used to this resolution. 我个人的看法: -再苦或杂乱是,最终用户体验将是更好的, 更大的 ,当我们习惯了这项决议。

Please share awesome techniques and design process. 请分享很棒的技术和设计过程。 Cheers !!! 干杯!!!

After Looking at possible solution for different UI Problems i found that Safe Area Layout guide introduced by apple with iOS 11 can help a lot. 在查看针对不同UI问题的可能解决方案之后,我发现苹果与iOS 11引入的安全区域布局指南可以提供很多帮助。

Note :- Safe area layout guide can be used even if your deployment target is less than iOS 11. 注意 : - 即使您的部署目标小于iOS 11,也可以使用安全区域布局指南。

safeAreaLayoutGuide replaces topLayoutGuide and bottomLayoutGuide as a new way to create constraints between your views and a superview. safeAreaLayoutGuide将topLayoutGuide和bottomLayoutGuide替换为在视图和superview之间创建约束的新方法。

  1. Add a launch image for iPhone X with 1125px × 2436px resolution 为iPhone X添加1125px×2436px分辨率的启动图像

  2. Go to your interface file, select identity inspector. 转到您的界面文件,选择身份检查器。 Enable Safe area as shown below. 启用安全区域,如下所示。 在此输入图像描述

  3. if you have a uiview pinned to the top of your view you can link its top constraint to safe area rather than superview. 如果您将uiview固定在视图的顶部,则可以将其顶部约束链接到安全区域而不是超级视图。

  4. Similarly for bottom view give bottom constraint to safe area instead of superview. 类似地,对于底部视图,给出安全区域而不是superview的底部约束。

在此输入图像描述

If you know how to create programmatic constraint you can use layout anchors to include safe area above your top view. 如果您知道如何创建编程约束,则可以使用布局锚点在顶视图上方包含安全区域。 You can thus link your layout to safe area programmatically. 因此,您可以以编程方式将布局链接到安全区域。

topView.topAnchor.constraint(
+  equalTo: view.safeAreaLayoutGuide.topAnchor
).isActive = true

UPDATE: Another scenario - Suppose you have a UIView at top of your screen. 更新:另一种情况 - 假设您在屏幕顶部有一个UIView。 you want this view to start below the notch in iPhoneX. 你希望这个视图从iPhoneX的缺口开始。 We need to calculate top margin on all iOS 11 devices and devices below iOS 11 as follows:- 我们需要计算iOS 11以下所有iOS 11设备和设备的最高保证金,如下所示: -

if (@available(iOS 11, *)) {
        UIWindow *window = UIApplication.sharedApplication.keyWindow;
        toppadding = 0.0;
        if (window.safeAreaInsets.top > 0)
        {
            toppadding = window.safeAreaInsets.top - 20;
        }
        //        CGFloat topPadding = window.safeAreaInsets.top;
        bottomPadding = window.safeAreaInsets.bottom;
        self.navigationViewTopConstraint.constant = toppadding;

    }
    else
    {
        bottomPadding = 0;
        self.navigationViewTopConstraint.constant = 0;
    }

Further Reading:- Here 进一步阅读: - 这里

Replacing Top and Bottom Layout guides in iOS 11 we have Safe Layout Guides to keep in mind when designing or updating autolayout for iPhone X . 在iOS 11中更换TopBottom布局指南时,我们在设计或更新iPhone X的自动 Safe Layout Guides时要记住Safe Layout Guides

Helpful resources (Apple Dev.) for adapting to iPhone X Display: 有用的资源(Apple Dev。)适用于iPhone X显示器:

According to Apple, respecting Safe Layout Guide will solve most of the auto-layout problems for iPhone X. Also according to the above videos from Apple, Landscape orientation layout would usually cause issues for iPhone X. Nevertheless it doesn't seem too difficult to cope with iPhone X display. 根据Apple的说法,尊重Safe Layout Guide将解决iPhone X的大多数自动布局问题。另外根据Apple的上述视频,横向布局通常会导致iPhone X出现问题。但是,它似乎并不太难应对iPhone X显示屏。

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

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