Unable to simultaneously satisfy constraints - No constraints in place

前端 未结 10 2012
野的像风
野的像风 2020-11-28 02:36

I have gone through and removed every single user constraint yet I am still getting the following error ONLY after I rotate the device. I have absolutely no

相关标签:
10条回答
  • 2020-11-28 03:17

    Its worth knowing the basics, and understand what Apple/Xcode is trying to tell you through the logs

    H = Horizontal constraint(for leading and Trailing)
    V = Vertical constraint(top and bottom edge)
    h = height
    w = width
    
    TopEdge    -> V:|-(points)-[VIEW:memoryAddress] 
    BottomEdge -> V:[VIEW:memoryAddress]-(points)-|
    Leading    -> H:|-(points)-[VIEW:memoryAddress] 
    Trailing   -> H:[VIEW:memoryAddress] -(points)-|
    height     -> h= --& v=--& V:[VIEW:memoryAddress((points)] 
    width      -> VIEW:memoryAddress.width == points 
    between    -> H:[VIEW 1]-(51)-[VIEW 2] 
    

    Once you understand this, reading your specific error is pretty easy

    0 讨论(0)
  • 2020-11-28 03:17

    I guess this is not a common error, but I solved it somewhat in a layman way. I was getting cryptic messages like the one above. To make sense of it, I created dummy view classes and attached it to the views in my storyboard. For example, if I had a UIView, I created a class called AddressView and attached it to this view in story board. Its a bit time consuming, but it worked for me. After that instead of object-ids, I got class names which helped me zero in on the views that were causing the issue very easily. My error message now read,

    2013-07-02 04:16:20.434 Myproject [2908:c07] 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:0x9edeae0 V:|-(0)-[AddressView:0x143ee020]   (Names: '|':MainView:0x129eb6a0 )>",
        "<NSAutoresizingMaskLayoutConstraint:0x11e998c0 h=--& v=--& V:[MainView:0x129eb6a0(704)]>",
        "<NSLayoutConstraint:0x156720b0 V:[AddressView:0x143ee020]-(896)-|   (Names: '|':MainView:0x129eb6a0 )>"
    )
    

    Here you can see, the names of my views MainView and Address view are causing the issue.

    To resolve it, I just moved my subview (in this case Address view) and repositioned it back. I think the issue began as I was using a mix of new Automatic Layour in Xcode 4.5 and old skills or manually positioning the views.

    Anyways, not sure if it was more luck than diligence, but nevertheless this could be a different way of debugging. Maybe this helps someone!

    0 讨论(0)
  • 2020-11-28 03:17

    This issue of the generated message "Unable to simultaneously satisfy contraints" in the debug console, is also experienced in XCode 9.4.
    In my particular instance on the iPad simulator, the message would generate:
    1) Only when placing the focus on a particular UITextField.
    2) Even with all view contraints removed.
    2) Even with all view contraints "Reset to Suggested Contraints".

    However, when the software keyboard was toggled on to display, the message would not be generated. Therefore, how much time should I spend on this issue, that in my instance is only generated when the software keyboard is toggled off.

    0 讨论(0)
  • 2020-11-28 03:18

    I've fixed this problem be deleting all translatesAutoresizingMaskIntoConstraints properties from xib file (Open xib as a source code).

    0 讨论(0)
  • 2020-11-28 03:21

    Let's look at these one by one.

    "<NSAutoresizingMaskLayoutConstraint:0x84543d0 h=--& v=--& V:[UIView:0xa330270(768)]>"

    This is saying view 0xa330270 (A) must be 768 points high.

    "<NSLayoutConstraint:0xa338350 V:[UIView:0xa331260]-(-1)-| (Names: '|':UIView:0xa330270 )>"

    This is saying view 0xa331260 (B)'s bottom edge must be a gap of -1 from the bottom of A, which is it's superview.

    "<NSLayoutConstraint:0xa338390 V:|-(841)-[UIView:0xa331260] (Names: '|':UIView:0xa330270 )>"

    This is saying that B's top edge must be a gap of 841 points from the top of its superview, A.

    These three things can't all be true - A can't be 768 points high, and contain a subview with a top edge 841 points inset from the top and -1 points inset from the bottom. Where have you defined each of these constraints?

    You haven't said what layout you are trying to achieve, but it looks like you might have an autoresizing mask on the superview that is preventing it changing in height when you rotate the device. As far as I know the autoresizing constraints only appear if you have added views programmatically, since a storyboard or xib is either all-autolayout, or not. Unless you are doing something like adding an auto laid out view (loaded from a nib?) to another view from a non-autolayout nib?

    0 讨论(0)
  • 2020-11-28 03:23

    I had this problem and took me 2 days to figure out the source of the problem....

    If you open a storyboard programmatically in you code just make sure you do it like this:

    UIStoryboard *story = [UIStoryboard storyboardWithName:@"MovieMaker" bundle:nil];
        UIViewController *vc = [story instantiateInitialViewController];
        //this causes layout to break [self presentViewController:vc animated:YES completion:nil];
        [self showViewController:vc sender:nil];
    

    I was using the commented line (using presentViewController) and the orientation bug has happening throwing constraints conflicts that weren't my constraints... changing to showViewController all constraints conflicts were gone and orientation works...... (I don't really know why it works with show and not present... still thinking it's... ALIENS...)

    0 讨论(0)
提交回复
热议问题