码迷,mamicode.com
首页 > 其他好文 > 详细

解决xib约束冲突

时间:2016-04-05 12:43:31      阅读:391      评论:0      收藏:0      [点我收藏+]

标签:

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

    技术分享

    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:

    技术分享

    • Find the proper UIView:

    技术分享

    • The next is to find NSLayoutConstraint we care about:

    技术分享

    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.

    技术分享

    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:

技术分享

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

技术分享

解决xib约束冲突

标签:

原文地址:http://www.cnblogs.com/piaojin/p/5354507.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!