Xcode6&7之iOS视图调试

在ios8以前,我们想要进行ui实时调试,可以依赖的技术手段有:

 用xcode启动app,然后点击xcode暂停运行按钮,然后在调试控制台输入下面语句:

po [[UIWindow keyWindow] recursiveDescription]

然后就可以看到完整的UI结构和层级关系,类似如下:

<UIWindow: 0x7b691cd0; frame = (0 0; 320 480); gestureRecognizers = <NSArray: 0x7b6921f0>; layer = <UIWindowLayer: 0x7b691e00>>

   | <UIView: 0x7c078b30; frame = (0 0; 320 480); autoresize = W+H; autoresizesSubviews = NO; layer = <CALayer: 0x7c078440>>

   |    | <UIView: 0x7c078ca0; frame = (10 87; 145 145); autoresize = RM+BM; autoresizesSubviews = NO; layer = <CALayer: 0x7c0786e0>>

   |    | <UIView: 0x7c078f20; frame = (165 87; 145 145); autoresize = RM+BM; autoresizesSubviews = NO; layer = <CALayer: 0x7c078630>>

   |    | <_UILayoutGuide: 0x7c079130; frame = (0 0; 0 20); hidden = YES; layer = <CALayer: 0x7c0792d0>>

   |    | <_UILayoutGuide: 0x7c079710; frame = (0 480; 0 0); hidden = YES; layer = <CALayer: 0x7c079790>>

po [self.view recursiveDescription]可以看到当前view下的ui结构,示例如下:

<UIView: 0x7ca8ceb0; frame = (0 0; 600 600); autoresize = RM+BM; autoresizesSubviews = NO; layer = <CALayer: 0x7ca8cb30>>

   | <UIView: 0x7ca73890; frame = (10 87; 285 285); autoresize = RM+BM; autoresizesSubviews = NO; layer = <CALayer: 0x7ca89200>>

   | <UIView: 0x7ca7f520; frame = (305 87; 285 285); autoresize = RM+BM; autoresizesSubviews = NO; layer = <CALayer: 0x7ca7ce70>>

   | <_UILayoutGuide: 0x7ca8bd30; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7ca814d0>>

   | <_UILayoutGuide: 0x7ca93b20; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7ca8d530>>

 另外reveal等工具也可以实现可视化分析ui的功能,该工具收费(有30天的免费试用期)。

在ios8/xcode6以后,苹果引入了新的技术手段支持我们进行实时ui调试;使用xcode运行app过程中,按下底部的Debug View Hierarchy 按钮,或者从菜单中选择Debug > View Debugging > Capture View Hierarchy 来启动视图调试:


启动视图调试后,Xcode会对应用程序的视图层次拍一个快照并展示三维原型视图来探究用户界面的层级。该三维视图除了展示app的视图层次外,还展示每个视图的位置、顺序和视图尺寸,以及视图间的交互方式。
该调试工具非常强大,结合storyboard一起使用可以很好的支撑ios开发的页面布局调整/性能优化等需求,具体的功能这里不一一展开,请开发人员在使用中进行总结和摸索。




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
完整高清+书签版,全面支持 Xcode 9, Swift 4.0,由于上传110MB的限制,要下源码,请移步至:http://download.csdn.net/download/a56562626206/10208625 Advanced Apple Debugging &amp; Reverse Engineering, Second Edition ISBN: Learn the powerful secrets of Apple&rsquo;s software debugger, LLDB, that can get more information out of any program than you ever thought possible. In Advanced Apple Debugging and Reverse Engineering, you&rsquo;ll come to realize debugging is an enjoyable process to help you better understand software. Not only will you learn to find bugs faster, but you&rsquo;ll also learn how other developers have solved problems similar to yours. You&rsquo;ll also learn how to create custom, powerful debugging scripts that will help you quickly find the secrets behind any bit of code that piques your interest. This book is for intermediate to advanced iOS/macOS developers who are already familiar with either Swift or Objective-C and want to take their debugging skills to the next level. Topics Covered in Advanced Apple Debugging &amp; Reverse Engineering: LLDB Max Achievement: Master LLDB and learn about its extensive list of subcommands and options. 1&rsquo;s and 0&rsquo;s: Learn the low-level components available to help extract useful information from a program, from assembly calling conventions to exploring the process of dynamically-loaded frameworks. The Power of Python: Use LLDB&rsquo;s Python module to create powerful custom debugging commands to introspect and augment existing programs. Nothing is Secret: Learn how to use DTrace, a dynamic tracing framework, and how to write D scripts to query anything you were ever curious about on your macOS machine. Case Studies: Quickly find and solve the real-world issues that iOS and macOS developers typically face in their day-to-day development workflow.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值