我正在创建一个简单的应用程序,我在屏幕底部有两行视图。在横向/更宽的屏幕上,我想将顶行放到底行。
| Portrait | | Landscape |
| AAAAAAAAAAAAAAAAAAAA | | AAAAAAAAAAAAAAAAAAAA |
| BBBBBBB CCCCCCC | | BBBBBBB CCCCCCC |
------------------------ -----------------------------------------
是否有几行Swift代码可以让我执行以下操作?
If (left edge of A) > (right edge of B) then set the (bottom of A to the Bottom of B)
注 1)A总是居中的 2)B和C的大小相同 3)B连接到左边缘 4)C附在右边缘
答案 0 :(得分:0)
当屏幕足够宽时,我找到了移动框架/组件的解决方案
@IBOutlet weak var aaaVertPosition: NSLayoutConstraint!
// in viewDidAppear
moveAaaStack
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
moveAaaStack()
}
func moveAaaStack() {
let aaaFrame: CGRect = selectedAaaOutlet.frame
let bbbFrame: CGRect = selectedBbbOutlet.frame
let leftEdgeOfAAA = aaaFrame.origin.x
let rightEdgeOfBBB = bosFrame.origin.x + bosFrame.size.width
print("AAA = \(leftEdgeOfAAA) & BBB = \(rightEdgeOfBBB)")
if (leftEdgeOfAAA + 8 > rightEdgeOfBBB) {
print("*** Moving AAA Stack down ***")
aaaVertPosition.constant = 8
} else {
print("*** Moving AAA Stack up ***")
aaaVertPosition.constant = 68.5
}
}