美文网首页iOS_踩坑笔记
约束冲突提示 self.translatesAutoresizi

约束冲突提示 self.translatesAutoresizi

作者: 半江瑟瑟 | 来源:发表于2017-11-14 17:52 被阅读72次

    更新2017-11-16
    这个方法不是根本解决约束冲突(其实不设置false能正常显示,只不过snapkit控制台打印太多日志),有时候你设置false,也是自动布局了,可能导致布局显示重叠了!,建议你还是从日志中分析原因;
    比如设置了 left 和 right 的约束,还提示width == 0 active,你可以尝试,设置left 和width,不要设置right!

    ======================================================================
    默认是true 自动布局设置为false 否则设置为true,不然导致ui显示错误或者控制台打印一堆信息
    ======================================================================

    api官方介绍
    /* By default, the autoresizing mask on a view gives rise to constraints that fully determine
    the view's position. This allows the auto layout system to track the frames of views whose
    layout is controlled manually (through -setFrame:, for example).
    When you elect to position the view using auto layout by adding your own constraints,
    you must set this property to NO. IB will do this for you.
    */
    @available(iOS 6.0, *)
    open var translatesAutoresizingMaskIntoConstraints: Bool // Default YES

    参考文章:

    translatesAutoresizingMaskIntoConstraints属性和autolayout有关,如果你定义的view想用autolayout,就将translatesAutoresizingMaskIntoConstraints设为NO,如果你使用的不是autolayout,就将translatesAutoresizingMaskIntoConstraints设为YES,对应关系如下
    autolayout translatesAutoresizingMaskIntoConstraints

    是                                NO
    
    否                                YES
    

    作者:小雨hahaha

    链接:http://www.jianshu.com/p/aca357d2bfd8

    http://ios.jobbole.com/86353/
    AutoresizingMask也是一种布局方式。这个想必大家都有了解。默认情况下,translatesAutoresizingMaskIntoConstraints = true, 此时视图AutoresizingMask会被转换成对应效果的约束。这样很可能就会和我们手动添加的其它约束有冲突。此属性设置成false时AutoresizingMask就不会变成约束。也就是说当前视图的AutoresizingMask失效了。

    ===============================

    self.translatesAutoresizingMaskIntoConstraints = false 父view设置这个属性false 控制台就不会打印下面的警告

    2017-11-14 17:27:36.448519+0800 SDJGQuestionbankProject[10435:6583063]

     注意////////[LayoutConstraints] 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)////////
    

    (

    "<NSAutoresizingMaskLayoutConstraint:0x170280230 h=--& v=--& SDJGQuestionbankProject.YKExamRulesMainView:0x13fd2e790.width == 0   (active)>",
    
    "<SnapKit.LayoutConstraint:
    

    0x1702a2c40@YKExamRulesMainView.swif

    t#190 UILabel:0x13fd6ff00.width <= SDJGQuestionbankProject.YKExamRulesMainView:0x13fd2e790.width - 114.0>"

    )

    Will attempt to recover by breaking constraint

    <SnapKit.LayoutConstraint:

    0x1702a2c40@YKExamRulesMainView.swif

    t#190 UILabel:0x13fd6ff00.width <= SDJGQuestionbankProject.YKExamRulesMainView:0x13fd2e790.width - 114.0>

    Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.

    The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

    2017-11-14 17:27:36.449982+0800 SDJGQuestionbankProject[10435:6583063] //[LayoutConstraints] 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)
    

    (

    "<NSAutoresizingMaskLayoutConstraint:0x170280230 h=--& v=--& SDJGQuestionbankProject.YKExamRulesMainView:0x13fd2e790.width == 0   (active)>",
    
    "<SnapKit.LayoutConstraint:
    

    0x1702ad920@YKExamRulesMainView.swif

    t#162 UILabel:0x13fe35030.width <= SDJGQuestionbankProject.YKExamRulesMainView:0x13fd2e790.width - 90.0>"

    )

    Will attempt to recover by breaking constraint

    <SnapKit.LayoutConstraint:

    0x1702ad920@YKExamRulesMainView.swif

    t#162 UILabel:0x13fe35030.width <= SDJGQuestionbankProject.YKExamRulesMainView:0x13fd2e790.width - 90.0>

    作者声明:我是小菜鸟,文章内容仅是自己在工作中总结、同事们的指导和网络搜索,难免有疏漏错误,大神们应用之后没有解决问题,我很抱歉;如能即时提出予以雅正,不胜感激.谢绝发泄式差评.欢迎交流分享,祝好.

    相关文章

      网友评论

        本文标题:约束冲突提示 self.translatesAutoresizi

        本文链接:https://www.haomeiwen.com/subject/fyvfvxtx.html