在我的iOS应用程序中的一个ViewControllers中,有一个具有此功能的UIButton:
@IBAction func openSettings(sender: AnyObject) {
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)
}
这是正常的,但是当从纵向更改为横向时,按钮不再起作用。我为此按钮使用自动布局。控制台说:
2016-06-05 17:15:31.238 MyApp[3975:1756888] 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.
(
"<_UILayoutSupportConstraint:0x15cf4a540 V:[_UILayoutGuide:0x15cf685a0(0)]>",
"<_UILayoutSupportConstraint:0x15cd5c7d0 V:|-(0)-[_UILayoutGuide:0x15cf685a0] (Names: '|':UIView:0x15e202490 )>",
"<NSLayoutConstraint:0x15cf68f60 V:[_UILayoutGuide:0x15cf685a0]-(265)-[UIButton:0x15cf65310'Enable Push!']>",
"<NSLayoutConstraint:0x15cf68fb0 UIButton:0x15cf65310'Enable Push!'.centerY == UIView:0x15e202490.centerY>",
"<NSLayoutConstraint:0x15cf4b640 'UIView-Encapsulated-Layout-Height' V:[UIView:0x15e202490(414)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x15cf68f60 V:[_UILayoutGuide:0x15cf685a0]-(265)-[UIButton:0x15cf65310'Enable Push!']>
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 :(得分:4)
你有两个相互争斗的限制。第一个
V:[_UILayoutGuide:0x15cf685a0]-(265)-[UIButton:0x15cf65310'Enable Push!']
正尝试从顶部布局指南中定位按钮265点。第二个:
UIButton:0x15cf65310'Enable Push!'.centerY == UIView:0x15e202490.centerY
尝试在视图中垂直居中按钮。确定是否要将按钮从顶部定位265个点或垂直居中,并删除其他约束。
答案 1 :(得分:2)
您收到此警告的原因是您没有为此按钮正确设置自动布局。您添加了一个不需要的额外约束。你可以删除顶部约束(265),因为你已经设置了按钮的高度并且对齐到垂直的视图中心。