﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-下雪天-文章分类-iOS</title><link>http://www.cppblog.com/longjun-9/category/20213.html</link><description>简单编程</description><language>zh-cn</language><lastBuildDate>Wed, 05 Jul 2017 14:56:16 GMT</lastBuildDate><pubDate>Wed, 05 Jul 2017 14:56:16 GMT</pubDate><ttl>60</ttl><item><title>iOS屏幕旋转控制心得(仅支持iOS6及其以上)</title><link>http://www.cppblog.com/longjun-9/articles/214619.html</link><dc:creator>Long</dc:creator><author>Long</author><pubDate>Fri, 20 Jan 2017 11:08:00 GMT</pubDate><guid>http://www.cppblog.com/longjun-9/articles/214619.html</guid><wfw:comment>http://www.cppblog.com/longjun-9/comments/214619.html</wfw:comment><comments>http://www.cppblog.com/longjun-9/articles/214619.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/longjun-9/comments/commentRss/214619.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/longjun-9/services/trackbacks/214619.html</trackback:ping><description><![CDATA[@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
&nbsp;如果app横屏适配没做好，是需要在少数页面支持横屏，那么可以用如下方法实现。<br />
<div><br />
</div>
<div>
<ol start="1">
    <li>在targets 的build settings界面如下设置</li>
</ol>
</div>
<div>&nbsp;<img src="http://www.cppblog.com/images/cppblog_com/longjun-9/1.png" width="707" height="293" alt="" /><br />
<br />
</div>
<div>这里为什么只需要Portrait？因为如果开启了Landscape，则在打开屏幕旋转锁的条件下，以横屏模式加载app，会导致app以横屏模式加载，这并不是几乎没做旋转适配的我们所希望的。</div>
<div><br />
</div>
<div>
<ol start="2">
    <li>在AppDelegate.m 中实现如下代理:</li>
</ol>
<div><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">- (</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #c35900;">UIInterfaceOrientationMask</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">)application:(</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #c35900;">UIApplication</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> *)application supportedInterfaceOrientationsForWindow:(</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #c35900;">UIWindow</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> *)window {<br />
&nbsp;&nbsp;&nbsp; </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #c35900;">UIInterfaceOrientationMask</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> orientations = </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #587ea8;">UIInterfaceOrientationMaskAllButUpsideDown</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">;<br />
&nbsp;&nbsp;&nbsp; </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">return</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> orientations;<br />
}<br />
</span>因为屏幕还是需要旋转,所以必须要这个代理里面的设置覆盖(1)中Device Orintation的全局设置.</div>
<div><br />
</div>
<div><br />
</div>
<div>3.实现如下两个扩展:</div>
<div><br />
</div>
<div><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #ff5af9;">#import </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #e82300;">&lt;UIKit/UIKit.h&gt;</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #ff5af9;"><br />
</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"><br />
</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">@interface</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> UITabBarController (AutoRotate)<br />
<br />
</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">@end</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"><br />
</span></div>
<div><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;"><br />
</span></div>
<div><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;"><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #ff5af9;">#import </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #e82300;">"UITabBarController+AutoRotate.h"</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #ff5af9;"><br />
</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"><br />
</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">@implementation</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> UITabBarController (AutoRotate)<br />
<br />
- (</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">BOOL</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">)shouldAutorotate<br />
{<br />
&nbsp;&nbsp;&nbsp; </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">return</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> [</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">self</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">.</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #587ea8;">selectedViewController</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #942192;">shouldAutorotate</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">];<br />
}<br />
<br />
- (</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #c35900;">NSUInteger</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">)supportedInterfaceOrientations<br />
{<br />
&nbsp;&nbsp;&nbsp; </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">return</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> [</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">self</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">.</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #587ea8;">selectedViewController</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #942192;">supportedInterfaceOrientations</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">];<br />
}<br />
<br />
- (</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #c35900;">UIInterfaceOrientation</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">)preferredInterfaceOrientationForPresentation<br />
{<br />
&nbsp;&nbsp;&nbsp; </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">return</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> [</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">self</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">.</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #587ea8;">selectedViewController</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #942192;">preferredInterfaceOrientationForPresentation</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">];<br />
}<br />
<br />
</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">@end</span></span></div>
<div><span style="font-size: 12px; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"><span style="font-variant-ligatures: no-common-ligatures;"><font color="#36568a"><br />
</font></span></span></div>
<div><span style="font-size: 12px; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"><span style="font-variant-ligatures: no-common-ligatures;"><font color="#36568a"><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #ff5af9;">#import </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #e82300;">&lt;UIKit/UIKit.h&gt;</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #ff5af9;"><br />
</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"><br />
</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">@interface</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> UINavigationController (AutoRotate)<br />
<br />
</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">@end</span></font></span></span></div>
<div><span style="font-size: 12px; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"><span style="font-variant-ligatures: no-common-ligatures;"><font color="#36568a"><br />
</font></span></span></div>
<div><span style="font-size: 12px; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"><span style="font-variant-ligatures: no-common-ligatures;"><font color="#36568a"><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #ff5af9;">#import </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #e82300;">"UINavigationController+AutoRotate.h"</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #ff5af9;"><br />
</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"><br />
</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">@implementation</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> UINavigationController (AutoRotate)<br />
<br />
- (</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">BOOL</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">)shouldAutorotate<br />
{<br />
&nbsp;&nbsp;&nbsp; </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">return</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> [</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">self</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">.</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #587ea8;">topViewController</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #942192;">shouldAutorotate</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">];<br />
}<br />
<br />
- (</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #c35900;">UIInterfaceOrientationMask</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">)supportedInterfaceOrientations<br />
{<br />
&nbsp;&nbsp;&nbsp; </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">return</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> [</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">self</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">.</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #587ea8;">topViewController</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #942192;">supportedInterfaceOrientations</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">];<br />
}<br />
<br />
<span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">// </span><span style="line-height: normal; font-family: 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">在支持多个方向的时候</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">,</span><span style="line-height: normal; font-family: 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">首次进入优先加载的方向</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">,</span><span style="line-height: normal; font-family: 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">在</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">iOS10</span><span style="line-height: normal; font-family: 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">下面没有调用</span><br />
- (</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #c35900;">UIInterfaceOrientation</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">)preferredInterfaceOrientationForPresentation<br />
{<br />
&nbsp;&nbsp;&nbsp; </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">return</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> [</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">self</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">.</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #587ea8;">topViewController</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;"> </span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #942192;">preferredInterfaceOrientationForPresentation</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #000000;">];<br />
}<br />
<br />
</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures;">@end</span></font></span></span></div>
<div><br />
</div>
<div><font face="Helvetica Neue">这两个扩展的作用:<br />
</font></div>
<div><font face="Helvetica Neue">在以UITabBarController或者UINavigationController作为根视图的时候,将旋转需要调用的三个接口shouldAutorotate,supportedInterfaceOrientations和preferredInterfaceOrientationForPresentation交给具体的UIViewController去实现.</font></div>
<div><font face="Helvetica Neue"><br />
</font></div>
<div>
<ol start="4">
    <li>在各个想要控制横竖屏的具体页面(UIViewController)上实现以下三个方法:</li>
</ol>
<div><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">// </span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: #38cb3c;"><font face="PingFang SC">最好都是YES,即使只支持竖屏,因为可能首次以横屏显示的时候不能在转动设备的情况下回到竖屏模式</font></span><br />
</div>
<div><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">- (</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">BOOL</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">)shouldAutorotate<br />
{<br />
&nbsp;&nbsp;&nbsp; </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">return</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">&nbsp;YES</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">;<br />
}</span></div>
<div><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"><br />
<span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">// </span><span style="line-height: normal; font-family: 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">支持的多个方向</span><br />
- (</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #c35900;">UIInterfaceOrientationMask</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">)supportedInterfaceOrientations<br />
{<br />
&nbsp;&nbsp;&nbsp; </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">return</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">&nbsp;XXX</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">;&nbsp;<br />
}<br />
<br />
<span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">// </span><span style="line-height: normal; font-family: 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">在支持多个方向的时候</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">,</span><span style="line-height: normal; font-family: 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">首次进入优先加载的方向</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">,</span><span style="line-height: normal; font-family: 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">在</span><span style="line-height: normal; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">iOS10</span><span style="line-height: normal; font-family: 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #38cb3c;">下面没有调用</span><br />
- (</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #c35900;">UIInterfaceOrientation</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">)preferredInterfaceOrientationForPresentation<br />
{<br />
&nbsp;&nbsp;&nbsp; </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">return</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">&nbsp;XXX;</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"><br />
}</span><br />
</div>
<font face="Helvetica Neue"></font></div>
<div><font face="Helvetica Neue"><br />
</font></div>
<div><font face="Helvetica Neue">为什么在UINavigationController中要用self.topViewController而不用self.visibleViewController? 因为self.visibleViewController返回的是最上层(最接近观察者)的页面,包括present出来的模态页面,而self.topViewController则是最上层的被push出来的页面.</font></div>
<div><font face="Helvetica Neue"><br />
</font></div>
<div><font face="Helvetica Neue">实验条件: 以UITabBarController作为根视图, 根视图下面挂两个UINavigationController, 两个UINavigationController的rootViewController分别是<span style="font-variant-ligatures: no-common-ligatures;">FirstViewController</span><span style="font-variant-ligatures: no-common-ligatures;"><font style="font-size: 12px;" face="Menlo">和</font><span style="font-variant-ligatures: no-common-ligatures;">SecondViewController</span><span style="font-variant-ligatures: no-common-ligatures;"><font style="font-size: 12px;" face="Menlo">,</font>FirstViewController push 出一个PushedViewController,&nbsp;SecondViewController present 一个PresentedViewController. 如下图:</span></span></font></div>
<div><font face="Helvetica Neue"><span style="font-variant-ligatures: no-common-ligatures;"><img src="http://www.cppblog.com/images/cppblog_com/longjun-9/2.png" width="818" height="776" alt="" /><br />
</span></font></div>
<div><font face="Helvetica Neue"><br />
</font></div>
<div><font face="Helvetica Neue">下面是我的实验结论:</font></div>
<div><font face="Helvetica Neue">&nbsp; &nbsp; (&nbsp;I )在UITabBarController的主界面,我想做到FirstViewController竖屏,SecondViewController横屏,然后再对应页面的三个方法中实现控制.&nbsp;</font><span style="font-family: 'Helvetica Neue';">其结果是, selectedViewController的方向会是接下来被selected的UIViewcontroller的方向,旋转以后才会固定在期望的方向上. 比如一开始</span><font style="font-family: 'Helvetica Neue';">FirstViewController是竖屏,点击tab bar 切换到SecondViewController,&nbsp;SecondViewController也会是竖屏; 然后旋转一下屏幕,&nbsp;SecondViewController变为横屏, 且在不切换tab bar的情况下,无论怎么旋转屏幕都是横屏; 然后再切到FirstViewController,&nbsp;FirstViewController变为横屏; 再旋转屏幕,&nbsp;FirstViewController变为竖屏,&nbsp;且在不切换tab bar的情况下,无论怎么旋转屏幕都是竖屏......</font></div>
<div><font face="Helvetica Neue">&nbsp; &nbsp; ( II )然后将FirstViewController和SecondViewController都固定为竖屏, 且在PushedViewController和PresentedViewController页面,我希望它们都是横屏, 然后再对应页面的三个方法中实现控制.&nbsp;由FirstViewController&nbsp;push出来的PushedViewController,其初始方向总是与FirstViewController一致, 所以刚开始加载的时候它是竖屏; 旋转屏幕,&nbsp;PushedViewController变成横屏且无法回到竖屏, 再pop 出PushedViewController,&nbsp;FirstViewController仍然是竖屏. &nbsp;由SecondViewController present出来的PresentedViewController, 正是我们需要的效果;&nbsp;dismiss&nbsp;PresentedViewController之后,&nbsp;SecondViewController的方向也与我们需要的一致.</font></div>
<div><font face="Helvetica Neue"><br />
</font></div>
<div><font face="Helvetica Neue">在测试( II )中, 把UINavigationController扩展中的self.topViewController换成self.topViewController, 其它不变, 则PushedViewController的初始方向也总是和FirstViewController一致,&nbsp;所以刚开始加载的时候它是竖屏;&nbsp;再pop 出PushedViewController,&nbsp;FirstViewController的方向由设备的方向决定, 经过旋转后回到竖屏,且无法再旋转成横屏. &nbsp;PresentedViewController的方向是我们需要的方向, 但是在dismiss&nbsp;PresentedViewController之后,&nbsp;SecondViewController的初始方向和PresentedViewController一致, 经过旋转以后回到竖屏,且无法再旋转成横屏.</font></div>
<div><font face="Helvetica Neue"><br />
</font></div>
<div><font face="Helvetica Neue"><span style="font-size: 11px; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"></span>所以,&nbsp;<font face="Helvetica Neue">在UINavigationController中使用self.topViewController与我们的期望最接近. 而且我还发现:</font></font></div>
<div><font face="Helvetica Neue">&nbsp;&nbsp; &nbsp;(1)不管<font face="Helvetica Neue">在UINavigationController中使用self.topViewController还</font>是使用self.visibleViewController, push&nbsp;PushedViewController时都不会调用PushedViewController中对应的三个方法,也就是说,这个时候PushedViewController的初始方向肯定和FirstViewController一致. 只有将设备旋转以后才会调用那三个方法(preferredInterfaceOrientationForPresentation在iOS 10中一直不调用,在其它版本中是否调用我还不清楚).</font></div>
<div><font face="Helvetica Neue"><font face="Helvetica Neue">&nbsp; &nbsp; (2)在使用self.visibleViewController的时候:pop PushedViewController或者dismiss PresentedViewController时,&nbsp;self.visibleViewController会指向一个神奇的类<span style="font-variant-ligatures: no-common-ligatures;">UISnapshotModalViewController, 不知道这个是类是什么.有兴趣大家可以探究一下.</span></font></font><br />
</div>
<div><font face="Helvetica Neue"><font face="Helvetica Neue"><span style="font-variant-ligatures: no-common-ligatures;"><br />
</span></font></font></div>
<div><font face="Helvetica Neue"><font face="Helvetica Neue"><span style="font-variant-ligatures: no-common-ligatures;">所以只剩下最后一个问题, 在push&nbsp;PushedViewController要怎么才能使设备强制旋转到对应的方向呢?</span></font></font></div>
<div><font face="Helvetica Neue"><font face="Helvetica Neue"><span style="font-variant-ligatures: no-common-ligatures;">不推荐使用performSelector强行调用UIDevice实例的setOrientation方法, 因为强调这个私有方法可能会导致审核被拒. 推荐使用UIDevice实例的 setValue:forKey:方法来强制旋转屏幕(Key传@"orientation&#8221;), 这个方法貌似没有调用私有API,因此不会被拒.但是比较有风险,因为随着iOS的升级, 这个字段很有可能会被改变,导致app crash. 可以用如下方法避免崩溃:</span></font></font></div>
<div><font face="Helvetica Neue"><span style="font-variant-ligatures: no-common-ligatures;"></span></font></div>
<div><font face="Helvetica Neue"><font face="Helvetica Neue"><span style="font-variant-ligatures: no-common-ligatures;"><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #c35900;">NSNumber</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> *value = [</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #c35900;">NSNumber</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #942192;">numberWithInt</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">:</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #587ea8;">UIInterfaceOrientationLandscapeLeft</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">];<br />
&nbsp;&nbsp;&nbsp; </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">@try</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [[</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #c35900;">UIDevice</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #942192;">currentDevice</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">] </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #942192;">setValue</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">:value </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #942192;">forKey</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">:</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #e82300;">@"orientation"</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">];<br />
&nbsp;&nbsp;&nbsp; } </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">@catch</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> (NSException *exception) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; } </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">@finally</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; }</span></span></font></font></div>
<div><font face="Helvetica Neue"><font face="Helvetica Neue"><span style="font-variant-ligatures: no-common-ligatures;">还有一种方法就是使用黑方法:</span></font></font></div>
<div><font face="Helvetica Neue"><font face="Helvetica Neue"><span style="font-variant-ligatures: no-common-ligatures;">在PushedViewController的viewDidLoad中加入这段代码, 即先present一个UIViewController, 然后马上dismiss:</span></font></font></div>
<div><font face="Helvetica Neue"><font face="Helvetica Neue"><span style="font-variant-ligatures: no-common-ligatures;"><br />
</span></font></font></div>
<div><font face="Helvetica Neue"><font face="Helvetica Neue"><span style="font-variant-ligatures: no-common-ligatures;"><span style="font-variant-ligatures: no-common-ligatures;"><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #c35900;">UIViewController</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> *vc1 = [[</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #c35900;">UIViewController</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #942192;">alloc</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">] </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #942192;">init</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">];<br />
&nbsp;&nbsp;&nbsp; [</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">self</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #942192;">presentViewController</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">:vc1 </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #942192;">animated</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">:</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">NO</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #942192;">completion</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">:</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">nil</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">];<br />
&nbsp;&nbsp;&nbsp; [vc1 </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #942192;">dismissViewControllerAnimated</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">:</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">NO</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #942192;">completion</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">:</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures; color: #36568a;">nil</span><span style="font-size: 12px; line-height: normal; font-family: Menlo; font-variant-ligatures: no-common-ligatures;">];</span></span></span></font></font></div>
<div><span style="font-variant-ligatures: no-common-ligatures;"><span style="font-variant-ligatures: no-common-ligatures;"><font face="Helvetica Neue">但是没有旋转的动画效果,比较生硬.</font></span></span></div>
<div><span style="font-variant-ligatures: no-common-ligatures;"><span style="font-variant-ligatures: no-common-ligatures;"><font face="Helvetica Neue"><br />
</font></span></span></div>
<div><span style="font-variant-ligatures: no-common-ligatures;"><span style="font-variant-ligatures: no-common-ligatures;"><font face="Helvetica Neue">还有最后一种方法, 就是用通过旋转View的transform属性来伪造屏幕旋转的假象,但我没尝试过,感觉会有各种诡异的问题.</font></span></span></div>
</div><img src ="http://www.cppblog.com/longjun-9/aggbug/214619.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/longjun-9/" target="_blank">Long</a> 2017-01-20 19:08 <a href="http://www.cppblog.com/longjun-9/articles/214619.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于UIButton选中和高亮状态下的图片切换</title><link>http://www.cppblog.com/longjun-9/articles/204838.html</link><dc:creator>Long</dc:creator><author>Long</author><pubDate>Mon, 16 Dec 2013 10:14:00 GMT</pubDate><guid>http://www.cppblog.com/longjun-9/articles/204838.html</guid><wfw:comment>http://www.cppblog.com/longjun-9/comments/204838.html</wfw:comment><comments>http://www.cppblog.com/longjun-9/articles/204838.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/longjun-9/comments/commentRss/204838.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/longjun-9/services/trackbacks/204838.html</trackback:ping><description><![CDATA[总结：<span style="font: 13.0px Arial">当button的状态为selected的时候，高亮时对应的状态应该是selected|highlighted，这与normal下高亮的状态</span><span style="font: 13.0px Arial"><span style="font: 13.0px Arial">highlighted</span>不同。<br /><br />以下是stackover上的提问，附上：<br /></span>I've a <code>UIButton</code> and I set it with:<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><span style="color: #000000; ">UIButton&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">myButton&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;[UIButton&nbsp;buttonWithType:UIButtonTypeCustom];<br /><br />UIImage&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">imageNormal&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;[UIImage&nbsp;imageNamed:</span><span style="color: #000000; ">@"</span><span style="color: #000000; ">normal.png</span><span style="color: #000000; ">"</span><span style="color: #000000; ">];<br />UIImage&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">imageNormalHover&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;[UIImage&nbsp;imageNamed:</span><span style="color: #000000; ">@"</span><span style="color: #000000; ">normalHover.png</span><span style="color: #000000; ">"</span><span style="color: #000000; ">];<br />UIImage&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">imageSelected&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;[UIImage&nbsp;imageNamed:</span><span style="color: #000000; ">@"</span><span style="color: #000000; ">selected.png</span><span style="color: #000000; ">"</span><span style="color: #000000; ">];<br />UIImage&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">imageSelectedHover&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;[UIImage&nbsp;imageNamed:</span><span style="color: #000000; ">@"</span><span style="color: #000000; ">selectedHover.png</span><span style="color: #000000; ">"</span><span style="color: #000000; ">];<br /><br />[myButton&nbsp;setImage:imageNormal&nbsp;forState:UIControlStateNormal];<br />[myButton&nbsp;setImage:imageSelected&nbsp;forState:UIControlStateSelected];<br /><br /></span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">&nbsp;(boolVar)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;[myButton&nbsp;setSelected:YES];<br />&nbsp;&nbsp;&nbsp;&nbsp;[myButton&nbsp;setImage:imageSelectedHover&nbsp;forState:UIControlStateHighlighted];<br />}&nbsp;</span><span style="color: #0000FF; ">else</span><span style="color: #000000; ">&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;[myButton&nbsp;setImage:imageNormalHover&nbsp;forState:UIControlStateHighlighted];<br />}</span></div>The issue is when the state is normal and I try to press the button I see correctly the image <code>normalHover.png</code> but when the state is selected and I try to press the button I see still <code>normalHover.png</code> and not the <code>selectedHover.png</code>. It seems that with <code>UIButton</code> I'm unable to change the highlighted image. Do you how to solve?<br /><br />Answer：<br />You need to set the image for the <code>UIControlStateSelected | UIControlStateHighlighted</code> combined state:<br /><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><span style="color: #000000; ">[myButton&nbsp;setImage:imageSelectedHover&nbsp;forState:(UIControlStateSelected&nbsp;</span><span style="color: #000000; ">|</span><span style="color: #000000; ">&nbsp;UIControlStateHighlighted)];</span></div>Because both states are on when the button is selected and you hignlight it by tapping on it.<img src ="http://www.cppblog.com/longjun-9/aggbug/204838.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/longjun-9/" target="_blank">Long</a> 2013-12-16 18:14 <a href="http://www.cppblog.com/longjun-9/articles/204838.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UITableViewCell高度变化的动画效果</title><link>http://www.cppblog.com/longjun-9/articles/203499.html</link><dc:creator>Long</dc:creator><author>Long</author><pubDate>Mon, 30 Sep 2013 02:02:00 GMT</pubDate><guid>http://www.cppblog.com/longjun-9/articles/203499.html</guid><wfw:comment>http://www.cppblog.com/longjun-9/comments/203499.html</wfw:comment><comments>http://www.cppblog.com/longjun-9/articles/203499.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/longjun-9/comments/commentRss/203499.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/longjun-9/services/trackbacks/203499.html</trackback:ping><description><![CDATA[闲话少说，上代码：<br /><br />改变cell高度的代码：<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">-</span><span style="color: #000000; ">&nbsp;(CGFloat)tableView:(UITableView&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">)tableView&nbsp;heightForRowAtIndexPath:(NSIndexPath&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">)indexPath&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;If&nbsp;our&nbsp;cell&nbsp;is&nbsp;selected,&nbsp;return&nbsp;double&nbsp;height</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">([self&nbsp;cellIsSelected:indexPath])&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;kCellHeight&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">2.0</span><span style="color: #000000; ">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;Cell&nbsp;isn't&nbsp;selected&nbsp;so&nbsp;return&nbsp;single&nbsp;height</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">return</span><span style="color: #000000; ">&nbsp;kCellHeight;<br />}</span></div><br />在点击cell时改变cell的高度，因此在didselect中添加关键语句：<br /><div class="container"><div class="line number1 index0 alt2"><code class="objc plain">[tableView beginUpdates];</code></div><div class="line number2 index1 alt1"><code class="objc plain">[tableView endUpdates];<br /></code><br /><code class="objc plain">didselect中的代码：<br /></code><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">-</span><span style="color: #000000; ">&nbsp;(</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">)tableView:(UITableView&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">)tableView&nbsp;didSelectRowAtIndexPath:(NSIndexPath&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">)indexPath&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;Deselect&nbsp;cell</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;[tableView&nbsp;deselectRowAtIndexPath:indexPath&nbsp;animated:TRUE];<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;Toggle&nbsp;'selected'&nbsp;state</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;BOOL&nbsp;isSelected&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;</span><span style="color: #000000; ">!</span><span style="color: #000000; ">[self&nbsp;cellIsSelected:indexPath];<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;Store&nbsp;cell&nbsp;'selected'&nbsp;state&nbsp;keyed&nbsp;on&nbsp;indexPath</span><span style="color: #008000; "><br /></span><span style="color: #000000; ">&nbsp;&nbsp;&nbsp;&nbsp;NSNumber&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">selectState </span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;[NSNumber&nbsp;numberWithBool:isSelected];<br />&nbsp;&nbsp;&nbsp;&nbsp;[selectedIndexes&nbsp;setObject:</span><span style="color: #000000; "><span style="color: #000000; "></span><span style="color: #000000; ">selectState</span> forKey:indexPath];<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;This&nbsp;is&nbsp;where&nbsp;magic&nbsp;happens...</span><span style="color: #008000; "><br /></span><span style="color: #000000;">&nbsp;&nbsp;&nbsp;&nbsp;[tableView&nbsp;beginUpdates];<br />&nbsp;&nbsp;&nbsp;&nbsp;[tableView&nbsp;endUpdates];<br />}</span></div></div></div>大功告成！<img src ="http://www.cppblog.com/longjun-9/aggbug/203499.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/longjun-9/" target="_blank">Long</a> 2013-09-30 10:02 <a href="http://www.cppblog.com/longjun-9/articles/203499.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于UIButton的isSelected方法返回值问题</title><link>http://www.cppblog.com/longjun-9/articles/203480.html</link><dc:creator>Long</dc:creator><author>Long</author><pubDate>Sun, 29 Sep 2013 01:33:00 GMT</pubDate><guid>http://www.cppblog.com/longjun-9/articles/203480.html</guid><wfw:comment>http://www.cppblog.com/longjun-9/comments/203480.html</wfw:comment><comments>http://www.cppblog.com/longjun-9/articles/203480.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/longjun-9/comments/commentRss/203480.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/longjun-9/services/trackbacks/203480.html</trackback:ping><description><![CDATA[我把UIButton放在UITableViewCell上，然后发现了一个很奇怪的问题，明明我在点击事件中修改了button的selected状态，但是下一次点击该button的时候，它的selected的BOOL值又是NO，就和第一次点击进去的时候一样。<br /><br />找原因都快找得崩溃了，最后发现，原来我在点击事件中刷新了tableView，这导致button的selected状态由YES随之改变为NO&#8230;&#8230;真是一个令人蛋疼的问题，找得我好苦啊~<img src ="http://www.cppblog.com/longjun-9/aggbug/203480.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/longjun-9/" target="_blank">Long</a> 2013-09-29 09:33 <a href="http://www.cppblog.com/longjun-9/articles/203480.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Using Open Source Static Libraries in Xcode 4</title><link>http://www.cppblog.com/longjun-9/articles/202580.html</link><dc:creator>Long</dc:creator><author>Long</author><pubDate>Fri, 16 Aug 2013 04:04:00 GMT</pubDate><guid>http://www.cppblog.com/longjun-9/articles/202580.html</guid><wfw:comment>http://www.cppblog.com/longjun-9/comments/202580.html</wfw:comment><comments>http://www.cppblog.com/longjun-9/articles/202580.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/longjun-9/comments/commentRss/202580.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/longjun-9/services/trackbacks/202580.html</trackback:ping><description><![CDATA[<a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/">http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/</a><br /><br /><p>Xcode 4.0.1 allows us to more easily create and use third party 
libraries in iOS projects. I think the process is still more complicated
 than it needs to be. Xcode&#8217;s documentation suggests that it should 
automatically detect implicit dependencies and index classes across 
workspaces but I have not found this to be the case. Here I&#8217;ll cover the
 steps I have found for creating and sharing code between projects and 
with other developers.<br />
<span id="more-3196"></span></p>
<ol><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#background">Background</a></li><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#using_a_static_library">Using a Static Library</a></li><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#creating_a_static_library">Creating a Static Library</a></li><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#future_improvements">Future Improvements</a></li></ol>
<p><a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="background"></a></p>
<h2>Background</h2>
<h3>Workspaces:</h3>
<p>Xcode 4 introduced the concept of <a href="http://developer.apple.com/library/ios/#featuredarticles/XcodeConcepts/Concept-Workspace.html">workspaces</a>
 as containers for multiple projects. There are a couple of key 
behaviors of workspaces which we want to build on when choosing how to 
share code across projects.</p>
<ul><li>By default, all the Xcode projects in a workspace are built in the same directory, referred to as the workspace build directory.</li><li>Xcode examines the files in the build directory to discover implicit dependencies.</li><li>Each project in a workspace continues to have its own independent identity.</li></ul>
<h3>Schemes:</h3>
<p>Within a workspace or within a project which is a member of a workspace we have <a href="http://developer.apple.com/library/ios/#featuredarticles/XcodeConcepts/Concept-Schemes.html">schemes</a>.
 Schemes replace the Active Target, Build Configuration, and Executable 
settings from Xcode 3 and define which targets to build, the order in 
which to build them, and what action to take when a build is complete. 
We&#8217;ll want our shared code to easily fit into the scheme of any projects
 which use it. The <a href="http://developer.apple.com/library/mac/#documentation/IDEs/Conceptual/Xcode4TransitionGuide/Orientation/Orientation.html#//apple_ref/doc/uid/TP40009984-CH5-SW26">Xcode 4 Transition Guide</a> covers this new structure in more detail.</p>
<h3>Targets:</h3>
<p>Within a scheme we have one or more build <a href="http://developer.apple.com/library/ios/#featuredarticles/XcodeConcepts/Concept-Targets.html">targets</a>
 which define a set of source files to build, the settings used to build
 those files, and any dependencies on the build products of other 
targets which must be completed first. Ultimately we would like a 
consumer of our code to be able to state that their project&#8217;s build 
target depends on our shared code and have Xcode build this shared code 
and make it available to the active build target. We can achieve that by
 providing a project containing the code to be shared and a static 
library build target which packages it into a build product other 
developers can add as a build target dependency.<br />
<a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="using_a_static_library"></a></p>
<h2>Using a static library</h2>
<ol><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#creating_a_workspace">Creating a workspace</a></li><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#adding_projects_to_a_workspace">Adding projects to a workspace</a></li><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#adding_build_target_dependencies">Adding build target dependencies</a></li><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#adding_the_static_librarys_headers">Adding the static library&#8217;s headers</a></li><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#configuring_the_projects_scheme">Configuring the project&#8217;s scheme</a></li><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#fixing_indexing">Fixing indexing</a></li></ol>
<p><a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="creating_a_workspace"></a></p>
<h3>Creating a workspace</h3>
<p>We can create a new empty workspace from Xcode&#8217;s file menu or open an
 existing project and select &#8220;Save As Workspace&#8230;&#8221; to create a new 
workspace containing our project. This will create a &#8220;.xcworkspace&#8221; 
package in the file system.</p>
<div id="attachment_3314" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/empty_workspace.png"><img class="size-medium wp-image-3314" title="empty workspace" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/empty_workspace.png?w=300" alt="An empty Xcode 4 workspace" height="147" width="300" /></a><p class="wp-caption-text">An empty Xcode 4 workspace</p></div><br />
<a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="adding_projects_to_a_workspace"></a>
<h3>Adding projects to a workspace</h3>
<p>Once we have a workspace we can right-click in the workspace&#8217;s 
navigator to create a new project or add an existing &#8220;.xcodeproj&#8221; 
package.</p>
<div id="attachment_3317" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/adding_a_project.png"><img class="size-medium wp-image-3317" title="adding a project" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/adding_a_project.png?w=300" alt="Adding a new project to a workspace" height="184" width="300" /></a><p class="wp-caption-text">Adding a new project to a workspace</p></div>
<div id="attachment_3318" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/adding_an_existing_project.png"><img class="size-medium wp-image-3318" title="adding an existing project" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/adding_an_existing_project.png?w=300" alt="Adding an existing project to a workspace" height="274" width="300" /></a><p class="wp-caption-text">Adding an existing project to a workspace</p></div>
<p>We want to end up with a single workspace containing our app&#8217;s 
project and the projects for any static libraries we are going to depend
 on. It is worth noting that these projects are all siblings in the 
workspace, our static libraries are not added as references within our 
app&#8217;s project.</p>
<p>&nbsp;<br />
<a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="adding_build_target_dependencies"></a></p>
<h3>Adding build target dependencies</h3>
<p>With all of the projects we need available in our workspace we can 
select our app&#8217;s build target and add a static library to the &#8220;Link 
Binary With Libraries&#8221; build phase.</p>
<div id="attachment_3319" class="wp-caption alignnone" style="width: 224px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/linkable_libraries.png"><img class="size-medium wp-image-3319" title="linkable libraries" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/linkable_libraries.png?w=214" alt="Libraries and frameworks available to add to the &quot;Link Binary With Libraries&quot; build phase" height="300" width="214" /></a><p class="wp-caption-text">Libraries and frameworks available to add to the "Link Binary With Libraries" build phase</p></div>
<div id="attachment_3320" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/linking_with_static_library.png"><img class="size-medium wp-image-3320" title="linking with a static library" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/linking_with_static_library.png?w=300" alt="A static library added to the &quot;Link Binary With Libraries&quot; build phase" height="170" width="300" /></a><p class="wp-caption-text">A static library added to the "Link Binary With Libraries" build phase</p></div><br />
<a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="adding_the_static_librarys_headers"></a>
<h3>Adding the static library&#8217;s headers</h3>
<p>We also need to make sure that our app&#8217;s build target can locate the 
public headers used in this static library. Open the &#8220;Build Settings&#8221; 
tab and locate the &#8220;User Header Search Paths&#8221; setting. Set this to 
&#8220;$(BUILT_PRODUCTS_DIR)&#8221; (or &#8220;$(BUILT_PRODUCTS_DIR)/static_library_name&#8221; 
if we want to be more specific but then we&#8217;ll have to update this 
setting every time we add another library) and check the &#8220;Recursive&#8221; 
check box. Now our built target will search our workspace&#8217;s shared build
 directory to locate linkable header files.</p>
<div id="attachment_3321" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/header_search_path_value.png"><img class="size-medium wp-image-3321" title="user header search paths value" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/header_search_path_value.png?w=300" alt="Setting the User Header Search Paths" height="194" width="300" /></a><p class="wp-caption-text">Setting the User Header Search Paths</p></div>
<div id="attachment_3322" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/set_user_header_search_paths.png"><img class="size-medium wp-image-3322" title="user header search paths set" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/set_user_header_search_paths.png?w=300" alt="User Header Search Paths set" height="147" width="300" /></a><p class="wp-caption-text">User Header Search Paths set</p></div>
<p>The &#8220;User Header Search Paths&#8221; setting defines the headers available 
as quoted imports (eg &#8220;#import &#8220;MyLibraryClass.h&#8221;) while the &#8220;Header 
Search Paths&#8221; setting defines those headers available as bracketed 
imports (eg &#8220;#import ). I&#8217;ve found that Xcode will only autocomplete 
header names in the quoted form so I always add libraries to the user 
header search path even though, from my project&#8217;s perspective, they 
might be more appropriate as system level (angle bracketed) libraries.</p>
<p>When using a static library which includes categories we will also 
have to add the &#8220;-ObjC&#8221; flag to the &#8220;Other Linker Flags&#8221; build setting. 
This will force the linker to load all objective-c classes and 
categories from the library. If the library contains only categories 
&#8220;-all_load&#8221; or &#8220;-force_load&#8221; may be needed as well. See <a href="http://developer.apple.com/library/mac/#qa/qa1490/_index.html">Technical Q&amp;A QA1490</a> for a more detailed explanation of these settings.<br />
<a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="configuring_the_projects_scheme"></a></p>
<h3>Configuring the project&#8217;s scheme</h3>
<p>At this point Xcode should have detected this implicit dependency 
between our app&#8217;s project and the static library&#8217;s project and have 
automatically configured our schemes correctly. Unfortunately I haven&#8217;t 
found this to be the case in practice. Instead we will have to edit our 
current scheme and add the static library&#8217;s build target before our 
app&#8217;s build target.</p>
<div id="attachment_3323" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/setting_target_build_order.png"><img class="size-medium wp-image-3323" title="setting target build order" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/setting_target_build_order.png?w=300" alt="Setting the scheme's target build order" height="205" width="300" /></a><p class="wp-caption-text">Setting the scheme's target build order</p></div><br />
<a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="fixing_indexing"></a>
<h3>Fixing indexing</h3>
<p>At this point we should be able to include headers from dependent 
static libraries, use the included classes, and still successfully build
 our app. Unfortunately Xcode will not show any classes from these 
linked static libraries in code completion despite the workspace 
documentation stating that &#8220;indexing is done across the entire 
workspace, extending the scope of content-aware features such as code 
completion and refactoring.&#8221;<br />
As a workaround we can drag the public headers from the static library&#8217;s
 project into our app&#8217;s project, adding them as references. These 
headers do not need to be included in any of our build targets, simply 
having references to the headers in our project will allow their classes
 to appear in code completion.<br />
<a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="creating_a_static_library"></a></p>
<h2>Creating a Static Library</h2>
<p>If we plan on releasing some of our own code for reuse as a static 
library there are several things we should do to make sure that the 
process described above is as easy and simple as possible for our 
library&#8217;s users.</p>
<ol><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#namespace_classes_appropriately">Namespace classes appropriately</a></li><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#create_a_build_target">Create a build target</a></li><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#expose_public_headers">Expose public headers</a></li><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#set_the_installation_directory">Set the installation directory</a></li><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#set_the_public_header_path">Set the public header path</a></li><li><a href="http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/#exclude_user_specific_files_from_vcs">Exclude user specific files from VCS</a></li></ol>
<p><a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="namespace_classes_appropriately"></a></p>
<h3>Namespace classes appropriately</h3>
<p>Use an appropriate <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingBasics.html#//apple_ref/doc/uid/20001281-1002226">prefix</a>
 for classes, protocols, functions, and constants in the library to 
prevent collisions with names in the library&#8217;s user&#8217;s project.<br />
<a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="create_a_build_target"></a></p>
<h3>Create a build target</h3>
<p>Provide a static library build target in the project for our users to
 link against. Xcode provides templates for creating projects with 
static libraries or adding static library build targets to existing 
projects.<br />
<a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="expose_public_headers"></a></p>
<h3>Expose public headers</h3>
<p>Determine which header files should be visible to users of the 
library. Provide a clearly named group containing these headers so that 
our library&#8217;s users can easily locate them as part of the workaround 
described in &#8220;Fixing Indexing&#8221; above. This also helps us clarify what 
the public interface our library provides is and what classes are 
implementation details which are likely to change as the library 
evolves.</p>
<p>For each public header file make sure it is set as &#8220;public&#8221; in the 
&#8220;Target Membership&#8221; section of the inspector pane. Only public headers 
are going to be available for our users to import.</p>
<div id="attachment_3326" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/making_headers_public.png"><img class="size-medium wp-image-3326" title="making headers public" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/making_headers_public.png?w=300" alt="Making a header file public" height="147" width="300" /></a><p class="wp-caption-text">Making a header file public</p></div><br />
<a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="set_the_installation_directory"></a>
<h3>Set installation directory</h3>
<p>Our static library build target is going to be a member of a user&#8217;s 
workspace and subject to that workspace&#8217;s installation rules. Our static
 library build product could therefore be installed in a location set by
 Xcode&#8217;s preferences, in the derived data path, or in a path specified 
by our build target. Since we can&#8217;t control the user&#8217;s settings we 
should make sure our library is well behaved in all cases. I set the 
&#8220;Installation Directory&#8221; build setting to &#8220;$(BUILT_PRODUCTS_DIR)&#8221; so 
that the static library build product can be found in a known location 
and set the &#8220;Skip Install&#8221; build setting to &#8220;Yes&#8221; to avoid accidentally 
installing iOS libraries into &#8220;/usr/local/lib&#8221;.</p>
<div id="attachment_3327" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/set_installation_directory.png"><img class="size-medium wp-image-3327" title="set installation directory" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/set_installation_directory.png?w=300" alt="Setting the installation directory" height="164" width="300" /></a><p class="wp-caption-text">Setting the installation directory</p></div><br />
<a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="set_the_public_header_path"></a>
<h3>Set the public header path</h3>
<p>We need to specify a location to copy our static library&#8217;s public 
headers to so that they can be included in our users&#8217; header search 
paths. Setting the &#8220;Public Headers Folder Path&#8221; to &#8220;$(TARGET_NAME)&#8221; will
 create a folder named after our static library build target in the 
workspace&#8217;s shared build directory and be indexed by the &#8220;User Header 
Search Paths&#8221; setting described above.</p>
<div id="attachment_3328" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.carbonfive.com/wp-content/uploads/2011/04/set_public_headers_path.png"><img class="size-medium wp-image-3328" title="set public headers path" src="http://blog.carbonfive.com/wp-content/uploads/2011/04/set_public_headers_path.png?w=300" alt="Setting the public headers path for the static library" height="147" width="300" /></a><p class="wp-caption-text">Setting the public headers path for the static library</p></div><br />
<a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="exclude_user_specific_files_from_vcs"></a>
<h3>Exclude user specific files from VCS</h3>
<p>Our workspace and project include a number of files which contain 
data relevant only to our user account; window positions, open files, 
and so on. There&#8217;s no need to check these into source control, at least 
not in our release branch, so let&#8217;s set some reasonable ignore rules in 
git or whatever VCS we are using. Github provides a convenient set of <a href="https://github.com/github/gitignore">.gitignore files</a><br />
<a style="width: 20px; height: 20px; text-indent: 20px; background-repeat: no-repeat; background-image: url(&quot;/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif&quot;);" name="future_improvements"></a></p>
<h2>Future Improvements</h2>
Hopefully Xcode 4 will eventually live up to the promise of it&#8217;s 
documentation and consistently auto-detect implicit dependencies and 
index files across the workspace correctly. There certainly seem to be a
 number of other developers struggling with this behavior:[<a href="https://devforums.apple.com/message/390470#390470">1</a>], [<a href="https://devforums.apple.com/message/399673#399673">2</a>], [<a href="https://devforums.apple.com/message/397932#397932">3</a>], [<a href="https://devforums.apple.com/message/399316#399316">4</a>], [<a href="https://devforums.apple.com/message/375741#375741">5</a>], [<a href="https://devforums.apple.com/message/377781#377781">6</a>], [<a href="http://stackoverflow.com/questions/5427396/whats-the-correct-way-to-configure-xcode-4-workspaces-to-build-dependencies-when">7</a>], [<a href="http://stackoverflow.com/questions/5483909/how-should-i-manage-dependencies-across-projects-in-an-xcode-workspace">8</a>].
 Until that indexing improves I find that this process is at least 
somewhat simpler and cleaner than trying to maintain simulator and 
device compatible static library builds in Xcode 3.<br />
I&#8217;ve found this pattern preferable to copying third party classes 
directly into my projects as it allows me to easily keep version history
 and make updates to static library projects in my workspace and avoids 
coupling my project too closely to the private structure and contents of
 the static library.<br />
Please let me know if you can see any areas where this pattern could be 
improved or if you&#8217;ve found your own alternative means of sharing code.<img src ="http://www.cppblog.com/longjun-9/aggbug/202580.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/longjun-9/" target="_blank">Long</a> 2013-08-16 12:04 <a href="http://www.cppblog.com/longjun-9/articles/202580.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Easy, Modular Code Sharing Across iPhone Apps: Static Libraries and Cross-Project References(简单，iPhone应用程序间模块化的代码共享：静态库和跨项目引用)</title><link>http://www.cppblog.com/longjun-9/articles/202579.html</link><dc:creator>Long</dc:creator><author>Long</author><pubDate>Fri, 16 Aug 2013 03:39:00 GMT</pubDate><guid>http://www.cppblog.com/longjun-9/articles/202579.html</guid><wfw:comment>http://www.cppblog.com/longjun-9/comments/202579.html</wfw:comment><comments>http://www.cppblog.com/longjun-9/articles/202579.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/longjun-9/comments/commentRss/202579.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/longjun-9/services/trackbacks/202579.html</trackback:ping><description><![CDATA[Finding an elegant way to reuse and share code (i.e., libraries) across 
separate iPhone applications can be a bit tricky at first, especially 
considering Apple&#8217;s restrictions on dynamic library linking and custom <a href="http://developer.apple.com/DOCUMENTATION/MacOSX/Conceptual/BPFrameworks/Concepts/WhatAreFrameworks.html#//apple_ref/doc/uid/20002303" target="_blank">Frameworks</a>. Most people agree that the best solution is to use <a href="http://en.wikipedia.org/wiki/Static_library" target="_blank">static libraries</a>. This tutorial builds on that solution, showing how your Xcode project can <em>reference a second Xcode project</em>&#8211;one
 which is used to build a static library. This allows you to 
automatically build that static library with the rest of your app, using
 your current build configuration (e.g., debug, release, etc.) and avoid
 pre-building several versions of the library separately (where each 
version was built for a specific environment/configuration).<br /><br /><h2>Problem: What&#8217;s the best way to share code across iPhone projects?</h2>
<p>If you want to reuse/share code across different iPhone applications, you only have two options (that I&#8217;m aware of):</p>
<ol><li>Copy all of the source code from the &#8220;shared&#8221; library into your own project</li><li>Keep the shared library code in a separate Xcode project and use it 
to build static libraries (e.g., libSomeLibrary.a, also referred to as 
&#8220;archive files&#8221;) that can be referenced by your project and used via 
static linking.</li></ol><p>The first option, copying the files, should be avoided when possible 
since it&#8217;s inherently redundant and contrary to the goal of keeping 
&#8220;common code&#8221; modular and atomic. It&#8217;s a much better idea to put the 
code in a <em><strong>static library</strong></em> since, as mentioned 
in the introduction, dynamic linking to custom libraries/frameworks 
isn&#8217;t allowed by Apple when it comes to iPhone apps. If you&#8217;re not sure 
how to put your code in a static library, I&#8217;d suggest taking a look at <a href="http://www.stormyprods.com/blogger/2008/11/using-static-libraries-with-iphone-sdk.html" target="_blank">this tutorial</a> on the Stormy Productions blog.</p><p>当拷贝文件本身就是冗余的，且和保持&#8220;通用代码&#8220;模块化和原子化的目标相悖，第一种方案就应该避免采用。<br /></p>
<p>So we&#8217;ve established that the second option is preferable, but 
there&#8217;s a catch: you&#8217;ll need to build and distribute multiple versions 
of the static library&#8211;one for each runtime environment and build 
configuration. For example, you would need to build both &#8220;release&#8221; and 
&#8220;debug&#8221; versions of the library for the Simulator, as well as other 
pairs for the iPhone or iPod device itself. How can we avoid manually 
pre-building and managing separate .a files?</p><br /><h2>Solution: Static libraries that are built on-demand via Xcode cross-project references</h2>
<p>The trick to avoid pre-building static libraries for each environment
 is to use an Xcode &#8220;cross-project reference&#8221; so that those libraries 
are built dynamically (i.e., when you build your own app) using your 
app&#8217;s current build configuration. This allows you to both reuse shared 
source code <em><strong>and</strong></em> avoid the headache of managing multiple versions of the library. Here&#8217;s how it works at a high level:</p><p>在build app的时候动态生成静态库。<br /></p>
<ol><li>The shared code lives in its own Xcode project that, when built, results in one or more static libraries.</li><li>You create an Xcode environment variable with a path to the directory that contains the static library&#8217;s *.xcodeproj file.</li><li>All iPhone apps that need the static library will use the aforementioned environment variable to <em><strong>reference</strong></em> the library&#8217;s Xcode project, including any static library in that project and the related header files.</li><li>Each time you build your project for a specific 
configuration/runtime environment, the shared project library will also 
be built for that config/environment&#8211;if it hasn&#8217;t already&#8211;and linked 
with your executable.</li></ol><p>In addition to solving the main problem (reusing code and avoiding 
management of multiple library versions), there are a couple of nice 
benefits to this strategy. First, if you make changes to the shared 
library source code, those changes will immediately be included the next
 time you build your own project (via the cross-project reference). 
Second, you can modify the Xcode environment variable to point to 
different versions of any project. For example, you might have separate 
directories for &#8220;somelibrary-1.0&#8243; and &#8220;somelibrary-2.0&#8243;; as you&#8217;ll see 
in the detailed solution instructions, it&#8217;s easy to modify the 
environment variable and switch your project to a different version of 
&#8220;somelibrary.&#8221;</p><p><br /></p><p><strong>Other Solutions</strong></p>
<h4>zerg-xcode</h4>
<p>Victor Costan has developed a slick command-line tool called &#8220;<a href="http://github.com/costan/zerg_xcode/tree/master" target="_blank">zerg-xcode</a>&#8221;
 which helps you copy the source code from one Xcode project (i.e., a 
static library project) into another Xcode project. In addition to 
physically copying the files, it inserts the targets from the &#8220;library&#8221; 
project into your &#8220;app&#8221; project. If the library project changes, you 
simply run zerg-xcode again with the approriate commands to sync the 
files and targets. Some people may find this tool very useful; my 
personal preference, however, is to avoid making any copies of the 
source code files and stick to Xcode&#8217;s built-in &#8220;cross-project 
reference&#8221; mechanism.</p>
<h4>&#8220;Fat&#8221; Universal Binary</h4>
<p>Another approach is to &#8220;bundle&#8221; two versions of a static library into
 a single file, referred to as a &#8220;fat&#8221; universal binary (see <a href="http://latenitesoft.blogspot.com/2008/10/iphone-programming-tips-building-unix.html" target="_blank">this post</a>
 on the Latenitesoft blog for an example). More specifically, one 
version of the library would be for the i386 architecture (i.e., the 
Simulator) and the second for the ARM architecture (i.e., the phone). 
This may be a perfectly fine solution for you if you really only need 
two versions, or if the source code for the library is kept private. 
That said, you&#8217;re still left with the task of maintaining pre-built 
versions of the libraries (plus the extra work of bundling them into the
 single file). In addition, I&#8217;m not sure that you can bundle more than 
two versions of the library into the binary (e.g., iPhone &#8220;release&#8221; and 
Simulator &#8220;release&#8221;, but not iPhone &#8220;debug&#8221; and Simulator &#8220;debug&#8221;).</p><img src ="http://www.cppblog.com/longjun-9/aggbug/202579.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/longjun-9/" target="_blank">Long</a> 2013-08-16 11:39 <a href="http://www.cppblog.com/longjun-9/articles/202579.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>IOS 项目加入FFMPEG库 --- FFMPEG+SDL学习 之 一</title><link>http://www.cppblog.com/longjun-9/articles/202244.html</link><dc:creator>Long</dc:creator><author>Long</author><pubDate>Tue, 30 Jul 2013 10:13:00 GMT</pubDate><guid>http://www.cppblog.com/longjun-9/articles/202244.html</guid><wfw:comment>http://www.cppblog.com/longjun-9/comments/202244.html</wfw:comment><comments>http://www.cppblog.com/longjun-9/articles/202244.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/longjun-9/comments/commentRss/202244.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/longjun-9/services/trackbacks/202244.html</trackback:ping><description><![CDATA[这个学习过程可谓是艰辛啊，只要是我把 FFMPEG 官网 上的一篇教程 <a href="http://ffmpeg.org/trac/ffmpeg/wiki/MacOSXCompilationGuide">MacOSXCompilationGuide</a> 误以为是指导生成ios通用库的教程了，其实这些库是用于Mac上开发应用程序的，官网上关于ios的教程好像还空着。<br />期待更新吧，我只好另觅途径了。<br /><br />这一次直接上我参考的教程吧：<br /><a href="http://witcheryne.iteye.com/blog/1734706"></a><a href="http://witcheryne.iteye.com/blog/1734706"><a href="http://witcheryne.iteye.com/blog/1734706"> </a></a><a href="http://witcheryne.iteye.com/blog/1734706">《Compile ffmpeg for iOS 6, support Simulator &amp; armv7 &amp; armv7s》</a><br /><br />这篇教程没讲什么配置，反正就是执行一下脚本，然后将生成的库和头文件移植到ios项目里面测试。<br />它也参考了我在《FFMPEG+SDL学习 之 二》中提到的那篇老外的blog。其实编译FFMPEG通用库最难的就是编译选项，很多编译选项都是专家级的，几乎没人解释为什么要开启或者关闭。<br />你可以用help命令粗略地看一下，或多或少有点帮助。<br /><br />我一开始是按照老外的那篇blog来手动配置编译环境的，但是后来发现少了个x264的库，再去编译一次又比较麻烦，所以就试了一下上面教程提到的shell脚本：<br /><a href="https://github.com/lvjian700/ffmpegc">https://github.com/lvjian700/ffmpegc</a>，<br />很简单，很傻瓜。<br />然后把生成的通用库和头文件移植到ios demo项目中 <a href="https://github.com/lvjian700/ffmpegc-demo">https://github.com/lvjian700/ffmpegc-demo</a>。<br />demo中的播放器只有图像没有声音，剩下的就需要我们自己去研究了。<br /><br />P.S.:我浪费了大量的时间来配置编译选项，想把Mac的编译配置选项用于ios，把能开得编译选项都开了，结果我发现我错了。它们两个的编译选项的交集少的可怜，搞得我最后都抓狂了，只能完全按照教程来&#8230;&#8230;<img src ="http://www.cppblog.com/longjun-9/aggbug/202244.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/longjun-9/" target="_blank">Long</a> 2013-07-30 18:13 <a href="http://www.cppblog.com/longjun-9/articles/202244.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>IOS 项目加入SDL库 --- FFMPEG+SDL学习 之 二</title><link>http://www.cppblog.com/longjun-9/articles/202243.html</link><dc:creator>Long</dc:creator><author>Long</author><pubDate>Tue, 30 Jul 2013 09:39:00 GMT</pubDate><guid>http://www.cppblog.com/longjun-9/articles/202243.html</guid><wfw:comment>http://www.cppblog.com/longjun-9/comments/202243.html</wfw:comment><comments>http://www.cppblog.com/longjun-9/articles/202243.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/longjun-9/comments/commentRss/202243.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/longjun-9/services/trackbacks/202243.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在学习FFMPEG的过程中遇到了SDL，但将SDL头文件引入ios项目的时候，发现找不到头文件 -_-！SDL加入项目是需要通用库和头文件的。我现在的需求是一个能适配iPhone4以上机型和模拟器的通用库。别急，先回忆一下各个机型和arm体系结构的关系:Armv6 --- iPhone3G (都老掉牙了，亲~)Armv7 --- iPhone3GS/4 or iPadArmv7s --- iPho...&nbsp;&nbsp;<a href='http://www.cppblog.com/longjun-9/articles/202243.html'>阅读全文</a><img src ="http://www.cppblog.com/longjun-9/aggbug/202243.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/longjun-9/" target="_blank">Long</a> 2013-07-30 17:39 <a href="http://www.cppblog.com/longjun-9/articles/202243.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于UISearchDisplayController的一些使用经验分享</title><link>http://www.cppblog.com/longjun-9/articles/200653.html</link><dc:creator>Long</dc:creator><author>Long</author><pubDate>Tue, 28 May 2013 11:42:00 GMT</pubDate><guid>http://www.cppblog.com/longjun-9/articles/200653.html</guid><wfw:comment>http://www.cppblog.com/longjun-9/comments/200653.html</wfw:comment><comments>http://www.cppblog.com/longjun-9/articles/200653.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/longjun-9/comments/commentRss/200653.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/longjun-9/services/trackbacks/200653.html</trackback:ping><description><![CDATA[1.&nbsp; UISearchDisplayController.searchResultsTableView 的frame指定只有在<code><span class="pln">didShowSearchResultsTableView</span><span class="pun">委托调用之后，反正我觉得系统会改动它的大小位置，所以我不得不写了一个重新定位它的frame，来覆盖系统的默认设置。<br /><br />2. </span></code>UISearchDisplayController.searchResultsTableView也能使用分组样式UITableViewStyleGrouped，只是没有现成的接口，你可以通过KVC机制修改它的私有变量_searchResultsTableViewStyle来达到目的。<br /><br />3. 关于修改no results标签的问题。我觉得网上的答案，包括stackoverflow上的答案，很多都忽略了一个问题：在shouldReloadTableForSearchString委托中找到searchResultsTableView的label成员，然后将label.text修改为自己想要的描述。但是在第一次加载的searchResultsTableView的时候，它还没有加载子视图，no result 标签会修改失败。所以要推迟相关的子视图检测代码的执行：<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">dispatch_time_t&nbsp;popTime&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000; ">&nbsp;dispatch_time(DISPATCH_TIME_NOW,&nbsp;</span><span style="color: #000000; ">0.001</span><span style="color: #000000; ">);<br />&nbsp;&nbsp;&nbsp;&nbsp;dispatch_after(popTime,&nbsp;dispatch_get_main_queue(),&nbsp;</span><span style="color: #000000; ">^</span><span style="color: #000000; ">(</span><span style="color: #0000FF; ">void</span><span style="color: #000000; ">){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">for</span><span style="color: #000000; ">&nbsp;(UIView&nbsp;</span><span style="color: #000000; ">*</span><span style="color: #000000; ">&nbsp;subview&nbsp;</span><span style="color: #0000FF; ">in</span><span style="color: #000000; ">&nbsp;self.searchDC.searchResultsTableView.subviews)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000FF; ">if</span><span style="color: #000000; ">&nbsp;([subview&nbsp;isKindOfClass:&nbsp;[UILabel&nbsp;</span><span style="color: #0000FF; ">class</span><span style="color: #000000; ">]])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;subview.hidden&nbsp;</span><span style="color: #000000; ">=</span><span style="color: #000000;">&nbsp;YES;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;});<br /></span></div><br />4. 关于修改背景searchResultsTableView背景的问题：使用UITableViewStyleGrouped总会有一些麻烦，我个人是这么认为的。反正我在viewDidLoad接口里修改背景颜色是不成功的，够来在UISearchBar的委托方法里修改成功了。在用UITableViewStyleGrouped风格的时候，别忘了这一句：searchResultsTableView.backgroundView = nil，没有它你修改不了背景颜色。<br /><br />5.一个关于searchResultsTableView的奇怪问题：搜索之后，我能得到searchResultsTableView正确的样式，但是在没有取消搜索的时候，我通过TabBar切换另一个页面（TabBar管理了两个页面，我搜索的是其中一个页面），然后再切回来，怪事发生了：<br />searchResultsTableView的宽和高都变为原来的两倍，我无法解释。<br /><br />6.didLoadSearchResultsTableView委托方法的问题：通过模拟器测试，我发现它只会在willUnloadSearchResultsTableView调用后调用，也就是在searchResultsTableView unload之后，而不是在searchResultsTableView 加载完之后，这让我觉得非常奇怪，因为它的命名跟它的行为完全不符。<img src ="http://www.cppblog.com/longjun-9/aggbug/200653.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/longjun-9/" target="_blank">Long</a> 2013-05-28 19:42 <a href="http://www.cppblog.com/longjun-9/articles/200653.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何在多台机器上共享IOS证书(转)</title><link>http://www.cppblog.com/longjun-9/articles/198269.html</link><dc:creator>Long</dc:creator><author>Long</author><pubDate>Thu, 07 Mar 2013 08:14:00 GMT</pubDate><guid>http://www.cppblog.com/longjun-9/articles/198269.html</guid><wfw:comment>http://www.cppblog.com/longjun-9/comments/198269.html</wfw:comment><comments>http://www.cppblog.com/longjun-9/articles/198269.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/longjun-9/comments/commentRss/198269.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/longjun-9/services/trackbacks/198269.html</trackback:ping><description><![CDATA[<div class="postbody">
		<p><span style="color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">1. 下载.cer文件到别的机器。就是在IDP上的那个。</span><br style="outline-style: none; outline-width: initial; outline-color: initial; color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">2. 从发送申请文件（certificate Request，后缀名为certSigningRequest）的机器上把证书对应的private key（.p12文件）导出，密码自己定，要记住，后面导入的时候要用。</span><br style="outline-style: none; outline-width: initial; outline-color: initial; color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">3. 在你需要的机器上安装证书（.cer），导入私钥文件(.p12)。安装对应App的provisioning profile。</span><br style="outline-style: none; outline-width: initial; outline-color: initial; color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">4. Over，你可以用其他机器开发了。</span></p>
<p><span style="color: #333333; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 24px; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;"><br /></span></p>
<p>注：必须得从申请机器上导出private key.到其他机器上</p>
<p><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">一、成员介绍</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;"><strong>1.&nbsp;&nbsp;&nbsp;&nbsp;Certification(证书)</strong></span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">证书是对电脑开发资格的认证，每个开发者帐号有一套，分为两种：</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">1)&nbsp;&nbsp;&nbsp;&nbsp;Developer Certification(开发证书)</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">安装在电脑上提供权限：开发人员通过设备进行真机测试。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">可以生成副本供多台电脑安装；</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">2)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Distribution Certification(发布证书)</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">安装在电脑上提供发布iOS程序的权限：开发人员可以制做测试版和发布版的程序。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">不可生成副本，仅有配置该证书的电脑才可使用；（副本制做介绍在下面Keychain中介绍）</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;"><strong>2.&nbsp;&nbsp;&nbsp;&nbsp;Provisioning Profile(授权文件)</strong></span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">授权文件是对设备如iPod Touch、iPad、iPhone的授权，文件内记录的是设备的UDID和程序的App Id，即使被授权的设备可以安装或调试Bundle identifier与授权文件中记录的App Id对应的程序。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">开发者帐号在创建授权文件时候会选择App Id，（开发者帐号下App Id中添加，单选）和UDID（开发者帐号下Devices中添加最多100个，多选）。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">授权文件分为两种，对应相应的证书使用：</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">1)&nbsp;&nbsp;&nbsp;&nbsp;Developer Provisioning Profile(开发授权文件)</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">在装有开发证书或副本的电脑上使用，开发人员选择该授权文件通过电脑将程序安装到授权文件记录的设备中，即可进行真机测试。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">注意：确保电脑有权限真机调试，即安装了开发证书或副本；在开发工具中程序的Bundle identifier和选中使用的授权文件的App Id要一致；连接调试的设备的UDID在选中的授权文件中有记录。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">2)&nbsp;&nbsp;&nbsp;&nbsp;Distribution Provisioning Profile(发布授权文件)</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">在装有发布证书的电脑上（即配置证书的电脑，只有一台）制做测试版和发布版的程序。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">发布版就是发布到App Store上的程序文件，开发者帐号创建授权文件时选择store选项，选择App Id，无需选择UDID；</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">测试版就是在发布之前交给测试人员可同步到设备上的程序文件，开发者帐号创建授权文件时选择AdHoc，选择App Id和UDID；只有选中的UDID对应的设备才可能安装上通过该授权文件制做的程序。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;"><strong>3.&nbsp;&nbsp;&nbsp;&nbsp;Keychain(开发密钥)</strong></span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">安
装证书成功的情况下证书下都会生成Keychain，上面提到的证书副本就是通过配置证书的电脑导出Keychain（就是.p12文件）安装到其他机子
上，让其他机子得到证书对应的权限。Developer 
Certification就可以制做副本Keychain分发到其他电脑上安装，使其可以进行真机测试。</span><br style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff;" /><span style="color: #323e32; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 21px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: #ffffff; display: inline !important; float: none;">注意：Distribution Certification只有配置证书的电脑才可使用，因此即使导出导出Keychain安装到其他电脑上，其他电脑也不可能具有证书的权限。</span></p>
		</div><img src ="http://www.cppblog.com/longjun-9/aggbug/198269.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/longjun-9/" target="_blank">Long</a> 2013-03-07 16:14 <a href="http://www.cppblog.com/longjun-9/articles/198269.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>