每个设备的快速布局

问题描述 投票:0回答:1

创建每个设备布局的最佳方式是什么?

现在我正在使用约束条件,但我不能让它正确.我所谓的gameView的宽度和高度太小了,不适合拼图块。

这是正确的宽度和高度,以适应iPhone 11的拼图片。

iPhone 11

而这是iPhone8上的风景iPhone 8

片数iPhone11 with puzzle piecesiPhone8 with puzzle pieces

我的解决方案是设置每个设备的框架尺寸,但我不知道这是否是正确的解决方案。我可以想象,有更好的解决方案。

      if UIDevice.current.deviceCategory() == .iPhone8 {
        turnOffConstraints()

        topView.frame = CGRect(x: 0, y: 0, width: topView.frame.width, height: 70)
        categoryLabel.frame = CGRect(x: 88, y: 23, width: 199, height: 35)
        totalMovesSV.frame = CGRect(x: 308, y: 78, width: 50.5, height: 44)
        timerSV.frame = CGRect(x: 20, y: 78, width: 50.5, height: 44)

        gameView.frame = CGRect(x: 20, y: 130, width: 335, height: 335)
        hintSV.frame = CGRect(x: 161, y: 473, width: 52, height: 80.5)

        backButtonSV.frame = CGRect(x: 52, y: 8, width: 52, height: 80.5)
        showOriginalButtonSV.frame = CGRect(x: 161, y: 8, width: 52, height: 80.5)
        levelsButtonSV.frame = CGRect(x: 275, y: 8, width: 52, height: 80.5)

        bottomView.frame = CGRect(x: 0, y: 567, width: topView.frame.width, height: 100)
    }

iphone8 pieces fits该应用程序正在工作,一切都适合像我想要的,但现在我的调试器充满了这种消息。

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. 2020-06-12 15:24:55.282095+0200 Sliding Game[35445:2539475] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)

我很好奇正确的方法是什么... ...

ios swift layout device
1个回答
0
投票

你给你的所有组件提供了恒定的值,它可能在某些设备上看起来不错,但并不意味着在所有设备上看起来都很好。160px 组件的高度。它在 iPhone XsMax 高度是896px)几乎占了屏幕的五分之一。但当你运行在 iPhone 5, SE.(高度为568px)几乎占了屏幕的四分之一。

给予恒定值会发生组件的交织。这就是Debug屏幕想说的。

你可以将组件估计到屏幕上,也可以使其相互锚定以避免它。

© www.soinside.com 2019 - 2024. All rights reserved.