简体   繁体   English

如何允许我的应用程序在所有 IOS 设备上可用

[英]How to allow for my app to be usable on all IOS devices

I am in the process of making my first IOS application using Xcode 11.4.我正在使用 Xcode 11.4 制作我的第一个 IOS 应用程序。 The idea for the app is very simple as I am still very much so in the learning phase.该应用程序的想法非常简单,因为我仍处于学习阶段。 Basically the concept is that the blocks of ice disappear at random and then reappear when they are clicked, the objective being to click the blocks that have disappeared before the time runs out and more blocks disappearing with each successive level.基本上,这个概念是冰块随机消失,然后在单击时重新出现,目的是在时间用完之前单击已经消失的块,并且每个连续的级别都会有更多的块消失。 I have included the image below of the storyboard for clarity.为清楚起见,我在下面附上了 storyboard 的图片。 Story Board picture The app works when I run it using an iphone 11 pro max simulator, however my issue is that it does not fit on the screen of smaller devices. Story Board picture当我使用 iphone 11 pro max 模拟器运行该应用程序时,该应用程序可以正常工作,但我的问题是它不适合较小设备的屏幕。 Since all of the blocks of ice are images, I tried adding a variety of constraints in order to make them fit however none of these worked with my images getting distorted and often appearing out of the view.由于所有的冰块都是图像,我尝试添加各种约束以使它们适合,但是这些都不适用于我的图像扭曲并且经常出现在视图之外。 I am unsure on how to properly add constraints or if this is even the proper way to proceed, any help would be appreciated.我不确定如何正确添加约束,或者这是否是正确的方法,我们将不胜感激。

You can also use 'Vary for traits' xCode tool to design app for different width/height ratio.您还可以使用 'Vary for traits' xCode 工具来设计不同宽度/高度比例的应用程序。
Please see image:请看图片:

在此处输入图像描述

You can also change constraints constant's programmatically based on device settings您还可以根据设备设置以编程方式更改约束常量

1 Create 'Device' struct that will detect your current device 1 创建将检测您当前设备的“设备”结构

struct Device {
static let IS_IPAD             = UIDevice.current.userInterfaceIdiom == .pad
static let IS_IPHONE           = UIDevice.current.userInterfaceIdiom == .phone
static let IS_RETINA           = UIScreen.main.scale >= 2.0

static let SCREEN_WIDTH        = Int(UIScreen.main.bounds.size.width)
static let SCREEN_HEIGHT       = Int(UIScreen.main.bounds.size.height)
static let SCREEN_MAX_LENGTH   = Int( max(SCREEN_WIDTH, SCREEN_HEIGHT) )
static let SCREEN_MIN_LENGTH   = Int( min(SCREEN_WIDTH, SCREEN_HEIGHT) )

static let IS_IPHONE_4              = IS_IPHONE && SCREEN_MAX_LENGTH <= 480 // 2, 3, 3GS, 4, 4S
static let IS_IPHONE_5              = IS_IPHONE && SCREEN_MAX_LENGTH == 568 // 5, 5S, 5C, SE
static let IS_IPHONE_6              = IS_IPHONE && SCREEN_MAX_LENGTH == 667 // 6, 6S, 7, 8
static let IS_IPHONE_6P             = IS_IPHONE && SCREEN_MAX_LENGTH == 736 // 6+, 6S+, 7+, 8+
static let IS_IPHONE_XS             = IS_IPHONE && SCREEN_MAX_LENGTH == 812 // X, XS, 11 Pro
static let IS_IPHONE_XS_MAX         = IS_IPHONE && SCREEN_MAX_LENGTH == 896 // XR, XS Max, 11, 11 Pro Max
static let IS_IPAD_PRO_11           = IS_IPAD && SCREEN_MAX_LENGTH == 1024 // iPad Pro 11"
static let IS_IPAD_PRO_13           = IS_IPAD && SCREEN_MAX_LENGTH == 1366 // iPad Pro 12.9"
}

2 Create IBOutlet for your constraint 2 为您的约束创建 IBOutlet

@IBOutlet private weak var myConstraint: NSLayoutConstraint!

3 Set constraint.constant programmatically based on current device 3 基于当前设备以编程方式设置 constraint.constant

if Device.isIphone5 {
    myConstraint.constant = 10 
}

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

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