解决方法
当旋转发生时,您需要以编程方式更新
UIStackView
的轴属性.文件说:
The exact layout varies depending on the stack view’s axis,
distribution,alignment,spacing,and other properties.
纯粹使用故事板无法实现这一目标.
工作方案
我创建了一个演示项目并验证它是否有效.我由一个视图控制器组成.
class ViewController: UIViewController { @IBOutlet weak var stackView: UIStackView! override func viewWillTransitionToSize(size: CGSize,withTransitionCoordinator coordinator:UIViewControllerTransitionCoordinator) { coordinator.animatealongsideTransition({ (context) -> Void in let orientation = UIApplication.sharedApplication().statusBarOrientation if orientation.isPortrait { self.stackView.axis = .Horizontal } else { self.stackView.axis = .Vertical } },completion: nil) } }
stackView是在故事板中创建的UIStackView,初始轴设置为Horizontal.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。