Reputation: 1774
Summary: I just got finished doing auto-layout and when I run it, it is all scrunched together. Then I look at the command prompt and it says the error above. I've tried googling it but it just shows solutions for Obj-C and I'm doing it in Swift. How would I be able to solve this auto-layout issue?
Error:
2014-10-20 00:07:41.102 Fraction Calculator[74247:6698760] 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:0x7c440f10 V:[UIButton:0x7c440db0'Divide It!'(30)]>",
"<NSLayoutConstraint:0x7af7bdb0 V:[UIImageView:0x7af7bae0(8)]>",
"<NSLayoutConstraint:0x7ae928b0 V:[UITextField:0x7ae952d0(30)]>",
"<NSLayoutConstraint:0x7ae97110 V:[UITextField:0x7ae96f70(30)]>",
"<NSLayoutConstraint:0x7ae97eb0 V:[UILabel:0x7ae97d70'Enter Your Fraction To Be...'(48)]>",
"<NSLayoutConstraint:0x7ae99cd0 V:[_UILayoutGuide:0x7ae990c0]-(0)-[UILabel:0x7ae97d70'Enter Your Fraction To Be...']>",
"<NSLayoutConstraint:0x7ae9a000 V:[UILabel:0x7ae97d70'Enter Your Fraction To Be...']-(41)-[UITextField:0x7ae96f70]>",
"<NSLayoutConstraint:0x7ae9a090 V:[UITextField:0x7ae96f70]-(14)-[UIImageView:0x7af7bae0]>",
"<NSLayoutConstraint:0x7ae9a150 V:[UIImageView:0x7af7bae0]-(13)-[UITextField:0x7ae952d0]>",
"<NSLayoutConstraint:0x7ae9a270 V:[UITextField:0x7ae952d0]-(59)-[UIButton:0x7c440db0'Divide It!']>",
"<NSLayoutConstraint:0x7ae9a2a0 V:[UIButton:0x7c440db0'Divide It!']-(50)-[UILabel:0x7ae98df0]>",
"<NSLayoutConstraint:0x7ae9a300 V:[UILabel:0x7ae98df0]-(166)-[_UILayoutGuide:0x7ae99680]>",
"<_UILayoutSupportConstraint:0x7c441e80 V:[_UILayoutGuide:0x7ae990c0(20)]>",
"<_UILayoutSupportConstraint:0x7c441770 V:|-(0)-[_UILayoutGuide:0x7ae990c0] (Names: '|':UIView:0x7af7abc0 )>",
"<_UILayoutSupportConstraint:0x7c443610 V:[_UILayoutGuide:0x7ae99680(0)]>",
"<_UILayoutSupportConstraint:0x7c4429d0 _UILayoutGuide:0x7ae99680.bottom == UIView:0x7af7abc0.bottom>",
"<NSLayoutConstraint:0x7c44acf0 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7af7abc0(480)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7ae97eb0 V:[UILabel:0x7ae97d70'Enter Your Fraction To Be...'(48)]>
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.
An Image of My Constraints https://www.dropbox.com/s/1l3ys9k7bdr8qrk/Screenshot%202014-10-20%2021.08.47.png?dl=0 An image of my iPhone 4 Preview https://www.dropbox.com/s/7uoulzppalex2r8/Screenshot%202014-10-20%2021.09.48.png?dl=0 Image of the iPhone 4 in the Simulator https://www.dropbox.com/s/c1qedgoytcnetri/iOS%20Simulator%20Screen%20Shot%20Oct%2020%2C%202014%2C%209.10.03%20PM.png?dl=0
If you guys have questions or need clarification please comment down below
Upvotes: 2
Views: 12913
Reputation: 2807
I had a hard time figuring out what constraints were causing this error. Here is a simpler way to do it.
I'm using Xcode 6.1.1
"Command + A" to select all the UILabels, UIImages etc. Click Editor -> Pin > (Select...) to Superview again click Editor -> Resolve Auto Layout Issues -> Add Missing Constraints or Reset to Suggested Constraints. It depends on your case.
Upvotes: 2
Reputation: 1938
It would be a bit hard to track which is the bad constraint by just looking at the error you have posted. But I can give a general rules or things to keep in mind while working with autolayout or constraints in general,
In your error, I see a lot of constraints which have fixed sizes, they would interfere when you have spacing constraint to those views. So start for the first, and keep the points I mentioned and delete the constraints you don't need.
References,
Upvotes: 6