从现在开始,我已经通过willRotatetoInterfaceOrIEntation和状态栏以编程方式实现了这一目标,以获得ipad方向.
使用Xcode 6,用于纵向和横向的iPhone布局是不同的,但对于iPad(常规,常规)是相同的.有可能通过限制来实现这些位置吗?
是的,你可以通过约束来做到这一点.首先,您需要为supervIEw创建约束,而不是最近的视图.相邻视图将改变位置,因此我们不希望约束相对于其他视图.有关如何设置约束的示例,请参阅下面的屏幕截图.
接下来,将您要修改的约束链接到IBOutlets,以便我们可以以编程方式修改它们.对于您的示例,这些将是约束:
@IBOutlet var greenVIEwTrailingConstraint: NSLayoutConstraint!@IBOutlet var greenVIEwBottomConstraint: NSLayoutConstraint!@IBOutlet var redVIEwtopConstraint: NSLayoutConstraint!@IBOutlet var redVIEwLeadingConstraint: NSLayoutConstraint!@IBOutlet var redVIEwBottomConstraint: NSLayoutConstraint!@IBOutlet var blueVIEwTrailingConstraint: NSLayoutConstraint!@IBOutlet var blueVIEwtopConstraint: NSLayoutConstraint!@IBOutlet var blueVIEwLeadingConstraint: NSLayoutConstraint!
最后,根据UIInterfaceOrIEntation更新约束常量.再次,使用您的示例,代码看起来像这样:
overrIDe func willRotatetoInterfaceOrIEntation(toInterfaceOrIEntation: UIInterfaceOrIEntation,duration: NSTimeInterval) { let padding: CGfloat = 16.0 // since we're calling this before the rotation,the height and wIDth are swapped let vIEwHeight = self.vIEw.frame.size.wIDth let vIEwWIDth = self.vIEw.frame.size.height // if landscape if UIInterfaceOrIEntationIsLandscape(toInterfaceOrIEntation) { greenVIEwTrailingConstraint.constant = (vIEwWIDth/2.0) + (padding/2.0) greenVIEwBottomConstraint.constant = padding blueVIEwtopConstraint.constant = (vIEwHeight/2.0) + (padding/2.0) blueVIEwTrailingConstraint.constant = padding blueVIEwLeadingConstraint.constant = (vIEwWIDth/2.0) + (padding/2.0) redVIEwtopConstraint.constant = padding redVIEwBottomConstraint.constant = (vIEwHeight/2.0) + (padding/2.0) redVIEwLeadingConstraint.constant = (vIEwWIDth/2.0) + (padding/2.0) } else { // else portrait greenVIEwBottomConstraint.constant = (vIEwHeight/2.0) + (padding/2.0) greenVIEwTrailingConstraint.constant = padding blueVIEwtopConstraint.constant = (vIEwHeight/2.0) + (padding/2.0) blueVIEwTrailingConstraint.constant = (vIEwWIDth/2.0) + (padding/2.0) blueVIEwLeadingConstraint.constant = padding redVIEwLeadingConstraint.constant = (vIEwWIDth/2.0) + (padding/2.0) redVIEwBottomConstraint.constant = padding redVIEwtopConstraint.constant = (vIEwHeight/2.0) + (padding/2.0) }}总结
以上是内存溢出为你收集整理的故事板和Swift中的不同肖像/风景视图全部内容,希望文章能够帮你解决故事板和Swift中的不同肖像/风景视图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)