如何对景观和肖像使用不同的约束

时间:2015-12-29 07:50:26

标签: ios autolayout

我想在风景和肖像上使用不同的布局,

但总是得到警告。

我的目标: enter image description here

我的解决方案:

添加一般约束:

   View A Left   = SuperView Left
   View A Top    = SuperView Top
   View A Bottom = SuperView Bottom

   View B Right  = SuperView Right 
   View B Top    = SuperView Top 
   View B Bottom = SuperView Bottom 
   View B Left   = View A Right

添加格局约束:

View A width =  superview Height + 30

添加肖像约束:

View A width = superView width

然后,

willRotateToInterfaceOrientation:duration:致电[self.view setNeedsUpdateConstraints];

updateViewConstraints 设置约束激活YES为横向/纵向,并将NO设置为另一个约束。

当我运行应用程序时,它可行, bur我得到了一些警告:

UITableView = View A, 
UIView (0x13ed098c0) = superView
UIView (0x174287080) = View B

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) 
(
    "<NSLayoutConstraint:0x174287030 'UIView-Encapsulated-Layout-Width' H:[UIView:0x13ed098c0(568)]>",
    "<NSLayoutConstraint:0x174287080 'UIView-Encapsulated-Layout-Height' V:[UIView:0x13ed098c0(239)]>",
    "<NSLayoutConstraint:0x17428a960 UITableView:0x13f0b2000.width == UIView:0x13ed098c0.width>",
    "<NSLayoutConstraint:0x170284dd0 UITableView:0x13f0b2000.width == UIView:0x13ed098c0.height + 30>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x174287080 'UIView-Encapsulated-Layout-Height' V:[UIView:0x13ed098c0(239)]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

如何在没有警告的情况下使其正常工作?

谢谢,

0 个答案:

没有答案