答案 0 :(得分:3)
您可以将UIStackView
与默认垂直方向一起使用,并在横向尺寸类中将其更改为水平,并使用分布Fill-Equally
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.current.orientation == .portrait
{
self.stackV.axis = .vertical
}
else
{
self.stackV.axis = .horizontal
}
}
答案 1 :(得分:0)
上述答案很完美,但我们也可以使用故事板处理它。解释我将3 UIView
加入stack view
以下属性。
现在,当我从landscape
模式转到portrait
时,屏幕的高度将从compact
转换为regular
。因此我们可以更改stack view axis
根据屏幕的高度变化vertical
到horizontal
。 gif 在视觉上解释你。
有关详细信息,请访问此link。