【发布时间】:2020-10-02 08:25:21
【问题描述】:
为每个设备创建布局的最佳方式是什么?
现在我正在处理约束,但我无法正确处理。 我所谓的 gameView 的宽度/高度太小,不适合拼图。
这是适合 iPhone 11 拼图的正确宽度/高度
我的解决方案是设置每个设备的帧大小 但我不知道这是否是正确的解决方案.. 我可以想象有更好的解决方案..
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)
}
该应用程序正在运行,一切都符合我的要求,但现在我的调试器充满了这种消息:
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)
我很好奇正确的方法是什么..
【问题讨论】: