iOS之旅--工具Reveal的使用

来源:互联网 发布:java将图片下载到jsp 编辑:程序博客网 时间:2024/05/16 11:54
</pre><p style="padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); max-width:100%; clear:both; min-height:1em; white-space:pre-wrap; font-family:'Helvetica Neue',Helvetica,'Hiragino Sans GB','Microsoft YaHei',微软雅黑,Arial,sans-serif; font-size:18px; line-height:28.7999992370605px; margin-top:1.2em!important; margin-bottom:1.2em!important; word-wrap:break-word!important">Reveal是一个iOS程序界面调试工具。使用Reveal,我们可以在iOS开发时动态地查看和修改应用程序的界面。</p><p style="padding-top:0px; padding-bottom:0px; color:rgb(51,51,51); max-width:100%; clear:both; min-height:1em; white-space:pre-wrap; font-family:'Helvetica Neue',Helvetica,'Hiragino Sans GB','Microsoft YaHei',微软雅黑,Arial,sans-serif; font-size:18px; line-height:28.7999992370605px; margin-top:1.2em!important; margin-bottom:1.2em!important; word-wrap:break-word!important">对于动态或复杂的交互界面,手写UI是不可避免的。通过Reveal,我们可以方便地调试和修改应用界面,免去了每次修改代码后重新启动的痛苦。</p><p></p><p><span style="font-size:18px;">1、首先需要下载Reveal工具,可以在下面链接下载<a target=_blank target="_blank" href="http://revealapp.com/download/">http://revealapp.com/download/</a></span></p><p><span style="font-size:18px;">2、下载之后,安装很简单,由于这个是app格式的,以下的方法是需要把它放在应用程序里面的。所以第二步需要拷贝下载好的app到 “应用程序”里面。</span></p><p><span style="font-size:18px;">3、接下来,如果是个人开发练习,可以直接采用静态链接的办法,这样会把Reveal 添加到工程中(不太适合团队开发)。下面提供官方教程链接:<a target=_blank target="_blank" href="http://support.revealapp.com/kb/getting-started/reveal-2">http://support.revealapp.com/kb/getting-started/reveal-2</a>,还可以使用动态链接的方法,<a target=_blank target="_blank" href="http://support.revealapp.com/kb/getting-started/revealrevealxcode">http://support.revealapp.com/kb/getting-started/revealrevealxcode</a></span></p><p><span style="font-size:18px;"></span></p><p><span style="font-size:18px;">如果不想把Reveal添加到Xcode工程中,可以使用下面官方提供的办法,<a target=_blank target="_blank" href="http://support.revealapp.com/kb/getting-started/revealxcodereveal">http://support.revealapp.com/kb/getting-started/revealxcodereveal</a>,此种方法说是只支持模拟器操作,不支持真机操作,</span></p><p><span style="font-size:18px;">然后还有另一种办法,我是从《iOS开发进阶》(唐巧 著)这本书中得知的,因为本人接触iOS时间不久,感觉看书可以快速得到很多技巧,所以买了两本书,加快了解iOS的开发及其一些技巧。</span></p><p><span style="font-size:32px;">下面介绍 模拟器中使用的办法,</span></p><p><span style="font-family:'Helvetica Neue',Helvetica,'Hiragino Sans GB','Microsoft YaHei',微软雅黑,Arial,sans-serif;font-size:18px;color:#333333;line-height:28.7999992370605px; white-space:pre-wrap">首先打开Terminal,输入</span><code style="margin:0px 0.15em; padding:0px 0.3em; max-width:100%; color:rgb(51,51,51); white-space:pre-wrap; font-size:0.85em; font-family:Consolas,Inconsolata,Courier,monospace; border:1px solid rgb(234,234,234); display:inline; word-wrap:break-word!important; background-color:rgb(248,248,248)">vim ~/.lldbinit</code><span style="font-family:'Helvetica Neue',Helvetica,'Hiragino Sans GB','Microsoft YaHei',微软雅黑,Arial,sans-serif;font-size:18px;color:#333333;line-height:28.7999992370605px; white-space:pre-wrap"> 会自动创建一个名为</span><code style="margin:0px 0.15em; padding:0px 0.3em; max-width:100%; color:rgb(51,51,51); white-space:pre-wrap; font-size:0.85em; font-family:Consolas,Inconsolata,Courier,monospace; border:1px solid rgb(234,234,234); display:inline; word-wrap:break-word!important; background-color:rgb(248,248,248)">.lldbinit</code><span style="font-family:'Helvetica Neue',Helvetica,'Hiragino Sans GB','Microsoft YaHei',微软雅黑,Arial,sans-serif;font-size:18px;color:#333333;line-height:28.7999992370605px; white-space:pre-wrap">的文件,然后将如下内容输入到该文件中:</span></p><p><span style="font-family:'Helvetica Neue',Helvetica,'Hiragino Sans GB','Microsoft YaHei',微软雅黑,Arial,sans-serif;font-size:18px;color:#333333;line-height:28.7999992370605px; white-space:pre-wrap"></span></p><pre name="code" class="objc">command alias reveal_load_sim expr (void*)dlopen("/Applications/Reveal.app/Contents/SharedSupport/iOS-Libraries/libReveal.dylib", 0x2);command alias reveal_load_dev expr (void*)dlopen([(NSString*)[(NSBundle*)[NSBundle mainBundle] pathForResource:@"libReveal" ofType:@"dylib"] cStringUsingEncoding:0x4], 0x2);command alias reveal_start expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStart" object:nil];command alias reveal_stop expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStop" object:nil];
{此处需要使用到的vim命令如下:

i 开始进入插入编辑模式

Esc 退出编辑模式

:wq 退出文件并保存

}

以上操作是为lldb设置了4个别名,为了后续方便操作,这4个别名意义如下:

  1. reveal_load_sim 为模拟器加载reveal调试用的动态链接库

  2. reveal_load_dev 为真机加载reveal调试用的动态链接库

  3. reveal_start 启动reveal调试功能

  4. reveal_stop 结束reveal调试功能

接下来,我们在AppDelegate类的 application: didFinishLaunchingWithOptions: 方法中,作如下3步操作(如下图所示):

  1. 点击该方法左边的行号区域,增加一个断点,之后右击该断点,选择“Edit Breakpoint”。

  2. 点击”Action”项边右的”Add Action”,然后输入“reveal_load_sim”

  3. 勾选上Options上的”Automatically continue after evaluating”选项。



之后我们运行模拟器,然后打开Reveal,就可以在Reveal界面的左上角,看到有模拟器可以连接调试,选择它,则可以在Reveal中查看和调试该iOS程序的界面了。


Reveal左上角选择模拟器就可以看到了。调试过程中,模拟器如果切换了界面,Reveal中只需要点击一下右上角的刷新按钮即可。


连接真机调试:

要用Reveal连接真机调试,我们需要先把Reveal的动态链接库上传到真机上。由于iOS设备有沙盒存在,所以我们只能将Reveal的动态链接库添加到工程中。

点击Reveal菜单栏的”Help”->”Show Reveal Library in Finder”选项(如下图所示),可以在Finder中显示出Reveal的动态链接库:libReveal.dylib

我们将libReveal.dylib文件拖动到目标Xcode工程中,Xcode默认情况下错误地将libReveal.dylib设置到了”Link Binary With Libraries”下,我们需要进行一下调整,将其中”Link Binary With Libraries”中删除,然后将其添加到“Copy Bundle Resources”下面。

之后用Reveal连接真机的方式和连接模拟器的方式类似,我们只需要把上一节提到的断点Action的内容从reveal_load_sim改成reveal_load_dev即可。


查看别人的app界面,此功能需要越狱,有兴趣的可以去下面链接看作者的方法:http://chuansong.me/n/1308113

以上内容收获与(唐巧)《iOS开发进阶》。

1 0
原创粉丝点击