解决xib约束冲突

  1. I would recommend to debug and find which constraint is "the one you don't want". Suppose you have following issue:

    enter image description here

    Always the problem is how to find following Constraints and Views.

    There are two solutions how to do this:

    1. DEBUG VIEW HIERARCHY (Do not recommend this way)

    Since you know where to find unexpected constraints (PBOUserWorkDayHeaderView) there is a way to do this fairly well. Lets find UIView and NSLayoutConstraint in red rectangles. Since we know their id in memory it is quite easy.

    • Stop app using Debug View Hierarchy:

    enter image description here

    • Find the proper UIView:

    enter image description here

    • The next is to find NSLayoutConstraint we care about:

    enter image description here

    As you can see, the memory pointers are the same. So we know what is going on now. Additionally you can find NSLayoutConstraint in view hierarchy. Since it is selected in View, it selected in Navigator also.

    enter image description here

    If you need you may also print it on console using address pointer:

    (lldb) po 0x17dce920
    <UIView: 0x17dce920; frame = (10 30; 300 24.5); autoresize = RM+BM; layer = <CALayer: 0x17dce9b0>>
    

    You can do the same for every constraint the debugger will point to you:-) Now you decide what to do with this.

  2. PRINT IT BETTER (I really recommend this way, this is of Xcode 7)

    • set unique identifier for every constraint in your view:

enter image description here

  • 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:

enter image description here

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

enter image description here

  • and quickly find it:

enter image description here

转载于:https://www.cnblogs.com/piaojin/p/5354507.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值