你可以标记,而不使用在故事板自动版式控制台输出的看法? [英] Can you label views in AutoLayout console output without using Storyboards?

查看:123
本文介绍了你可以标记,而不使用在故事板自动版式控制台输出的看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看通过自动版式的WWDC会谈,我已经了解到,有StoryboardID对你的看法设置使得约束控制台输出冲突更易于阅读(即你得到一个名称,而不是只是一个地址)。他们告诉你在哪里设置在Interface Builder中StoryboardID(以前只是标识符),但有没有办法做到这一点在code?我试图调试大型和复杂的一套,我没有写我自己,在一个应用程序,是100%的方案,有很多不可满足的约束的意见,这是(在某种程度上)在iOS的7个工作,但开始打破iOS版8.我很想得到一个清晰的画面,其中<的UIView:0x8675309> 实际上是造成问题的原因。

我看了看UIView类参考,不标识或StoryboardID中找到。

但假如答案是没有太惊讶。毕竟,它被称为是有原因的一个Storyboard ID。但我想AP preciate确认和解决方法,使自动版式控制台转储如果可能的话更具有可读性。


解决方案

  

我很想得到一个清晰的画面这实际上是造成问题的原因。


我有两个建议。


  1. 在X code,应用同样的运行期间($ P $你得到被赋予某种关于限制控​​制台转储后pferably右),选择调试 - >查看调试 - >捕获视图层次。

    该应用程序的停顿,你显示你的视图层次。选择一个视图,你都显示在Object Inspector中的内存地址。当你发现其地址为 0x8675309 一,这是一个。另外,你可以看到的限制,在大小检查这一观点立场。


  2. 实施约束记录器实用程序我在书中提供。第二个报告的标识符和约束沿着视图层次结构。


下面是公用事业;他们之间,我已经保存困惑时间:

 扩展NSLayoutConstraint {
    类FUNC reportAmbiguity(VAR五:UIView的?){
        如果v == {为零
            V = UIApplication.sharedApplication()。keyWindow
        }
        对于以V VV!.subviews为[UIView的] {
            的println(\\(VV)\\(vv.hasAmbiguousLayout()))
            如果vv.subviews.count> 0 {
                self.reportAmbiguity(VV)
            }
        }
    }
    类FUNC listConstraints(VAR五:UIView的?){
        如果v == {为零
            V = UIApplication.sharedApplication()。keyWindow
        }
        对于以V VV!.subviews为[UIView的] {
            让ARR1 = vv.constraintsAffectingLayoutForAxis(.Horizo​​ntal)
            让ARR2 = vv.constraintsAffectingLayoutForAxis(.Vertical)
            的NSLog(\\ n \\ n%@ \\ nH的:%@ \\ NV:%@,VV,ARR1,ARR2);
            如果vv.subviews.count> 0 {
                self.listConstraints(VV)
            }
        }
    }
}

I'm watching through the WWDC talks on AutoLayout, and I've learned that having StoryboardID set on your views makes the console output for constraint conflicts much easier to read (i.e. you get a name instead of just an address). They show you where to set the StoryboardID (formerly just "Identifier") in Interface Builder, but is there a way to do it in code? I'm trying to debug a large and complicated set of views that I didn't write myself, in an app that's 100% programmatic, that has many unsatisfiable constraints, and that was (somehow) working in iOS 7 but started breaking in iOS 8. I would love to get a clear picture of which <UIView:0x8675309> is actually causing the problem.

I looked over the UIView class reference, no "Identifier" or "StoryboardID" to be found.

Wouldn't be too surprised if the answer is "nope". After all it's called a Storyboard ID for a reason. But I would appreciate a confirmation, and a workaround to make the AutoLayout console dump more readable if possible.

解决方案

I would love to get a clear picture of which is actually causing the problem.

I have two suggestions.

  1. In Xcode, during the same run of the app (preferably right after you get are given some sort of console dump about the constraints), choose Debug -> View Debugging -> Capture View Hierarchy.

    The app pauses and you are shown your view hierarchy. Select a view and you are shown its memory address in the Object Inspector. When you find the one whose address is 0x8675309, that's the one. Plus you can see the constraints that position this view in the Size Inspector.

  2. Implement the constraint logger utilities that I provide in my book. The second one reports the view hierarchy along with the identifiers and the constraints.

Here are the utilities; between them, I've saved hours of puzzlement:

extension NSLayoutConstraint {
    class func reportAmbiguity (var v:UIView?) {
        if v == nil {
            v = UIApplication.sharedApplication().keyWindow
        }
        for vv in v!.subviews as [UIView] {
            println("\(vv) \(vv.hasAmbiguousLayout())")
            if vv.subviews.count > 0 {
                self.reportAmbiguity(vv)
            }
        }
    }
    class func listConstraints (var v:UIView?) {
        if v == nil {
            v = UIApplication.sharedApplication().keyWindow
        }
        for vv in v!.subviews as [UIView] {
            let arr1 = vv.constraintsAffectingLayoutForAxis(.Horizontal)
            let arr2 = vv.constraintsAffectingLayoutForAxis(.Vertical)
            NSLog("\n\n%@\nH: %@\nV:%@", vv, arr1, arr2);
            if vv.subviews.count > 0 {
                self.listConstraints(vv)
            }
        }
    }
}

这篇关于你可以标记,而不使用在故事板自动版式控制台输出的看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆