简体   繁体   中英

Can I just ignore “Unable to simultaneously satisfy constraints”?

I'm updating an existing app to autolayout to support more device sizes. I have a few objects which need to animate and instead of working with constrains I set them to:

self.secondCounter.translatesAutoresizingMaskIntoConstraints = YES //example

to use the old setFrame methods.

This seems to work but throws an runtime error on first animation:

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) ( "", "", "" )

Will attempt to recover by breaking constraint

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful. 2014-10-07 19:41:12.903 AppName[5018:1153922] 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) ( "", "", "" )

Will attempt to recover by breaking constraint

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

In fact I don't get this message because I don't set any constrains on this object (I heard Xcode sets them per default on build for every view in an auto layout xib).

But somehow everything looks good and seems to work.

Can I just ignore this message or will I run into problems later?

You will definitely run into problems later and need to resolve this. If you don't satisfy all your constraints and the runtime correction system can't 'fudge the numbers', it can cause your app to crash. You can get nasty messages like this one:

Fatal Exception: NSInvalidArgumentException. Unable to create description in descriptionForLayoutAttribute_layoutItem_coefficient. Something is nil

In order to solve autolayout issues, follow some simple steps:

  1. Find the view with the offending layouts. They will have a yellow or red icon by the View Controller's name in the left-side list of storyboard objects in the upper-right:

黄色图标是你的向导......

  1. Resolve the issues by changing the frames, the constraints, or adding new constraints. The issues themselves each come with an explanation, and you can find an excellent tutorial here: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/ResolvingIssues/ResolvingIssues.html
  2. When you have resolved all your issues, make sure you test! Test your view under the iPhone 4, 5, 6 and 6 Plus sizes in the simulator, and iPad if appropriate. Also, be sure to test under iOS 7 and 8 - some autolayout conventions are fine in iOS 8 but crash iOS 7 apps. (Learned that the hard way...)

That's it! Find, fix, test :)

IMHO, The exception is a red herring.

The constraints are implicitely managed by apple. At some point a few lines of code 'over there' can indirectly affect them and thus it's a pain to discover why your code is raising an exception 'over here'

In my case i discovered a [cell setHidden:YES] went ahead and replaced that code with [cell removeFromSuperview] and the problem went away.

.... One of the tenants of OO programing is to make the APIS safe and easy to use. Not easily bruised and confused.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM