AutoLayout, Unable to simultaneously satisfy constraints

前端 未结 6 464
粉色の甜心
粉色の甜心 2020-12-02 08:22

Just started learning iOS AutoLayout, Interface builder very straight forward, but when I try to archive the same thing on the code

    [self.view addConstr         


        
6条回答
  •  天命终不由人
    2020-12-02 09:00

    The easiest way how to find unsatisfiable constraints:

    • set unique identifier for every constraint in your view:

    • create simple extension for NSLayoutConstraint:

    SWIFT:

    extension NSLayoutConstraint {
    
        override public var description: String {
            let id = identifier ?? ""
            return "id: \(id), constant: \(constant)" //you may print whatever you want here
        }
    }
    

    OBJECTIVE-C

    @interface NSLayoutConstraint (Description)
    
    @end
    
    @implementation NSLayoutConstraint (Description)
    
    -(NSString *)description {
        return [NSString stringWithFormat:@"id: %@, constant: %f", self.identifier, self.constant];
    }
    
    @end
    
    • build it once again, and now you have more readable output for you:

    • once you got your id you can simple tap it in your Find Navigator:

    • and quickly find it:

    HOW TO SIMPLE FIX THAT CASE?

    • try to change priority to 999 for broken constraint.

    See the related answer here: Unable to simultaneously satisfy constraints, will attempt to recover by breaking constraint

提交回复
热议问题