<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iPhoneGeek 爱疯极客 &#187; 编程</title>
	<atom:link href="http://www.iphone-geek.cn/category/%e7%bc%96%e7%a8%8b/feed" rel="self" type="application/rss+xml" />
	<link>http://www.iphone-geek.cn</link>
	<description>iPhone 新闻，编程，技巧与提示，代码，教程</description>
	<lastBuildDate>Thu, 08 Dec 2011 01:18:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>iOS 5设备下UINavigationbar的背景修改</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/ios-5%e8%ae%be%e5%a4%87%e4%b8%8buinavigationbar%e7%9a%84%e8%83%8c%e6%99%af%e4%bf%ae%e6%94%b9</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/ios-5%e8%ae%be%e5%a4%87%e4%b8%8buinavigationbar%e7%9a%84%e8%83%8c%e6%99%af%e4%bf%ae%e6%94%b9#comments</comments>
		<pubDate>Thu, 08 Dec 2011 01:17:26 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[用户界面]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[iOS 5]]></category>
		<category><![CDATA[UINavigationbar]]></category>
		<category><![CDATA[代码片段]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1198</guid>
		<description><![CDATA[最近我突然发现UINavigationbar背景修改的方法不起作用了，代码如下：
123456789@implementation UINavigationBar &#40;CustomImage&#41;

-&#40;void&#41;drawRect:&#40;CGRect&#41;rect 
&#123;
&#160; &#160; UIImage *image = &#91;UIImage imageNamed:@&#34;navigationbar.png&#34;&#93;;
&#160; &#160; &#91;image drawInRect:CGRectMake&#40;0,0,self.frame.size.width,self.frame.size.height&#41;&#93;;
&#125;

@end
发现原来是iOS 5的原因，如果运行在iOS 5以下的版本就没有问题了。经过实验以下方法适合iOS 5（放在ViewDidLoad中）：
123&#160; &#160; if &#40;&#91;self.navigationController.navigationBar respondsToSelector:@selector&#40; setBackgroundImage:forBarMetrics:&#41;&#93;&#41;&#123;
&#160; &#160; &#160; &#160; &#91;self.navigationController.navigationBar setBackgroundImage:&#91;UIImage imageNamed:@&#34;navigationbar.png&#34;&#93; forBarMetrics:UIBarMetricsDefault&#93;;
&#160; &#160; &#125;
第一条if语句的作用是防止程序在iOS 5以下的版本中崩溃。
这样，依靠这两段代码，我的UINavigationbar的背景问题在iOS 5及以下版本中得到了完美的解决。
]]></description>
			<content:encoded><![CDATA[<p>最近我突然发现UINavigationbar背景修改的方法不起作用了，代码如下：</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">@implementation</span> UINavigationBar <span style="color: #002200;">&#40;</span>CustomImage<span style="color: #002200;">&#41;</span><br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>rect <br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; UIImage <span style="color: #002200;">*</span>image <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;navigationbar.png&quot;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>image drawInRect<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0,0,self.frame.size.width,self.frame.size.height<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>发现原来是iOS 5的原因，如果运行在iOS 5以下的版本就没有问题了。经过实验以下方法适合iOS 5（放在ViewDidLoad中）：</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>self.navigationController.navigationBar respondsToSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span> setBackgroundImage<span style="color: #002200;">:</span>forBarMetrics<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.navigationController.navigationBar setBackgroundImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;navigationbar.png&quot;</span><span style="color: #002200;">&#93;</span> forBarMetrics<span style="color: #002200;">:</span>UIBarMetricsDefault<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>第一条if语句的作用是防止程序在iOS 5以下的版本中崩溃。</p>
<p>这样，依靠这两段代码，我的UINavigationbar的背景问题在iOS 5及以下版本中得到了完美的解决。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/ios-5%e8%ae%be%e5%a4%87%e4%b8%8buinavigationbar%e7%9a%84%e8%83%8c%e6%99%af%e4%bf%ae%e6%94%b9/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>创建iOS 5 News Stand应用程序之一 &#8211; 外观</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%88%9b%e5%bb%baios-5-news-stand%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e4%b9%8b%e4%b8%80-%e5%a4%96%e8%a7%82</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%88%9b%e5%bb%baios-5-news-stand%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e4%b9%8b%e4%b8%80-%e5%a4%96%e8%a7%82#comments</comments>
		<pubDate>Fri, 21 Oct 2011 02:52:06 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[用户界面]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[Newsstand]]></category>
		<category><![CDATA[提示与技巧]]></category>
		<category><![CDATA[教程]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1189</guid>
		<description><![CDATA[iOS 5提供了一个新的framework &#8211; Newsstand framework，它允许把应用程序运行于News Stand中。实际上，News Stand相当于一个特制的文件夹专门放置报纸，杂志类应用程序。由于时间有限，这里我分几个部分介绍这一技术。

首先介绍的就是怎样把一个应用程序改变成一个News Stand程序，这实际上有两步工作，一是让程序运行于News Stand，二是改变程序的图标。

1. 让程序运行于News Stand内

可以在Info.plist中添加

12&#60;key&#62;UINewsstandApp&#60;/key&#62;
&#160; &#60;true/&#62;

或者直接在Xcode中更改Info.plist（如图）：



就这么简单，运行！你的程序就运行在News Stand中了。


不过，出现在News Stand中的是一个非常丑陋的白色方框。这一定不是你需要的效果。那么，我们需要第二步。

2. 为你的News Stand程序添加图标

应用程序仍需定义标准图标，这些图标用于settings，search，Push等，（而且你的程序有可能运行于iOS 5以前的版本）。Newsstand 图标可以反应应用的内容，可以动态更新，另外还可以加一些修饰，使其看上去就像真正的杂志或者报纸。

你可以直接修改Info.plist

12345678910111213141516171819&#60;key&#62;CFBundleIcons&#60;/key&#62;
&#60;dict&#62;
&#160; &#160; &#60;key&#62;CFBundlePrimaryIcon&#60;/key&#62;
&#160; &#160; &#60;dict&#62;
&#160; &#160; &#160; &#160; &#60;key&#62;CFBundleIconFiles&#60;/key&#62;
&#160; &#160; &#160; &#160; &#60;array&#62;
&#160; &#160; &#160; &#160; &#160; &#160; &#60;string&#62;Icon.png&#60;/string&#62;
&#160; &#160; &#160; &#160; &#160; &#160; &#60;string&#62;Icon@2x.png&#60;/string&#62;
&#160; &#160; &#160; &#160; &#60;/array&#62;
&#160; &#160; &#60;/dict&#62;
&#160; &#160; &#60;key&#62;UINewsstandIcon&#60;/key&#62;
&#160; &#160; &#60;dict&#62;
&#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>iOS 5提供了一个新的framework &#8211; Newsstand framework，它允许把应用程序运行于News Stand中。实际上，News Stand相当于一个特制的文件夹专门放置报纸，杂志类应用程序。由于时间有限，这里我分几个部分介绍这一技术。<br />
<br class="spacer_" /><br />
首先介绍的就是怎样把一个应用程序改变成一个News Stand程序，这实际上有两步工作，一是让程序运行于News Stand，二是改变程序的图标。<br />
<span id="more-1189"></span></p>
<h2>1. 让程序运行于News Stand内</h2>
<p><br class="spacer_" /><br />
可以在Info.plist中添加</p>
<blockquote>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>UINewsstandApp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;true</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></td></tr></tbody></table></div>
</blockquote>
<p>或者直接在Xcode中更改Info.plist（如图）：<br />
<br class="spacer_" /><br />
<a href="http://www.iphone-geek.cn/wp-content/uploads/2011/10/s1.jpg"><img class="aligncenter size-full wp-image-1190" title="s1" src="http://www.iphone-geek.cn/wp-content/uploads/2011/10/s1.jpg" alt="s1" width="680" height="203" /></a><br />
<br class="spacer_" /><br />
就这么简单，运行！你的程序就运行在News Stand中了。</p>
<p style="text-align: center;"><a href="http://www.iphone-geek.cn/wp-content/uploads/2011/10/s2.jpg"><img class="aligncenter size-full wp-image-1191" title="s2" src="http://www.iphone-geek.cn/wp-content/uploads/2011/10/s2.jpg" alt="s2" width="651" height="414" /></a></p>
<p><br class="spacer_" /><br />
不过，出现在News Stand中的是一个非常丑陋的白色方框。这一定不是你需要的效果。那么，我们需要第二步。<br />
<br class="spacer_" /></p>
<h2>2. 为你的News Stand程序添加图标</h2>
<p><br class="spacer_" /><br />
应用程序仍需定义标准图标，这些图标用于settings，search，Push等，（而且你的程序有可能运行于iOS 5以前的版本）。Newsstand 图标可以反应应用的内容，可以动态更新，另外还可以加一些修饰，使其看上去就像真正的杂志或者报纸。<br />
<br class="spacer_" /><br />
你可以直接修改Info.plist</p>
<blockquote>
<div class="codecolorer-container xml mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CFBundleIcons<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CFBundlePrimaryIcon<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CFBundleIconFiles<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Icon.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Icon@2x.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>UINewsstandIcon<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CFBundleIconFiles<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>NewsstandIcon1.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>NewsstandIcon1@2x.png<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
</blockquote>
<p><br class="spacer_" /><br />
或者直接使用Xcode编辑：<br />
<br class="spacer_" /><br />
<a href="http://www.iphone-geek.cn/wp-content/uploads/2011/10/s3.jpg"><img class="aligncenter size-full wp-image-1192" title="s3" src="http://www.iphone-geek.cn/wp-content/uploads/2011/10/s3.jpg" alt="s3" width="517" height="240" /></a><br />
<br class="spacer_" /><br />
关于BindingType和BindingEdge应该很容易理解，我就不知赘述了。另外Newsstand中的图标不一定是正方形，只是不知有没有尺寸上的限制。<br />
<br class="spacer_" /><br />
<a href="http://www.iphone-geek.cn/wp-content/uploads/2011/10/s4.jpg"><img class="aligncenter size-full wp-image-1193" title="s4" src="http://www.iphone-geek.cn/wp-content/uploads/2011/10/s4.jpg" alt="s4" width="398" height="264" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%88%9b%e5%bb%baios-5-news-stand%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e4%b9%8b%e4%b8%80-%e5%a4%96%e8%a7%82/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>强迫UIView以某种方向显示的秘诀</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%bc%ba%e8%bf%abuiview%e4%bb%a5%e6%9f%90%e7%a7%8d%e6%96%b9%e5%90%91%e6%98%be%e7%a4%ba%e7%9a%84%e7%a7%98%e8%af%80</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%bc%ba%e8%bf%abuiview%e4%bb%a5%e6%9f%90%e7%a7%8d%e6%96%b9%e5%90%91%e6%98%be%e7%a4%ba%e7%9a%84%e7%a7%98%e8%af%80#comments</comments>
		<pubDate>Thu, 25 Aug 2011 06:29:53 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[用户界面]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[提示与技巧]]></category>
		<category><![CDATA[代码片段]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1182</guid>
		<description><![CDATA[我有一个项目其中某些UIView必须以特定的方向（Portrait或者Landscape）显示。这个看似简单的问题，困惑了我很久，直到今天我才完全找到解决的方法。

为简单起见，我以一个简单的例子说明一下我的问题。我有一个允许各种方向知道旋转的RootViewController，它包括一个共三行的UITableView，第一行显示“Portrait”，第二行显示“Landscape”，第三行显示“Autorotation”，点击某些行后，使用pushViewController打开一个DetailViewController，这个View Controller控制的view将根据行的内容有所不同。比如，如果按下的是第一行，则在DetailViewController中显示“Portrait”，并只允许UIView以portrait方式显示。

首先，我根据按下的行号，以orientation作为参数，传递给DetailViewController，在此ViewController的shouldAutorotateToInterfaceOrientation方法中根据orentation参数返回。代码如下：

1234567891011&#160;- &#40;BOOL&#41;shouldAutorotateToInterfaceOrientation:&#40;UIInterfaceOrientation&#41;interfaceOrientation
&#123;
&#160; &#160; if &#40; self.orientation == 0 &#41; // allow portrait
&#160; &#160; &#160; &#160; return &#40;interfaceOrientation == UIInterfaceOrientationPortrait&#41; &#124;&#124; &#40;interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown&#41;;
&#160; &#160; else if &#40; self.orientation == 1 &#41; &#160;// allow landscape
&#160; &#160; &#123; &#160; &#160; &#160; &#160;
&#160; &#160; &#160; &#160; return &#40;interfaceOrientation == UIInterfaceOrientationLandscapeLeft&#41; &#124;&#124; &#40;interfaceOrientation == UIInterfaceOrientationLandscapeRight&#41;;
&#160; &#160; &#125;
&#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>我有一个项目其中某些UIView必须以特定的方向（Portrait或者Landscape）显示。这个看似简单的问题，困惑了我很久，直到今天我才完全找到解决的方法。<br />
<span id="more-1182"></span><br />
为简单起见，我以一个简单的例子说明一下我的问题。我有一个允许各种方向知道旋转的RootViewController，它包括一个共三行的UITableView，第一行显示“Portrait”，第二行显示“Landscape”，第三行显示“Autorotation”，点击某些行后，使用pushViewController打开一个DetailViewController，这个View Controller控制的view将根据行的内容有所不同。比如，如果按下的是第一行，则在DetailViewController中显示“Portrait”，并只允许UIView以portrait方式显示。<br />
<br class="spacer_" /><br />
首先，我根据按下的行号，以orientation作为参数，传递给DetailViewController，在此ViewController的shouldAutorotateToInterfaceOrientation方法中根据orentation参数返回。代码如下：<br />
<br class="spacer_" /></p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>shouldAutorotateToInterfaceOrientation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIInterfaceOrientation<span style="color: #002200;">&#41;</span>interfaceOrientation<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> self.orientation <span style="color: #002200;">==</span> <span style="color: #2400d9;">0</span> <span style="color: #002200;">&#41;</span> <span style="color: #11740a; font-style: italic;">// allow portrait</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#40;</span>interfaceOrientation <span style="color: #002200;">==</span> UIInterfaceOrientationPortrait<span style="color: #002200;">&#41;</span> || <span style="color: #002200;">&#40;</span>interfaceOrientation <span style="color: #002200;">==</span> UIInterfaceOrientationPortraitUpsideDown<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> self.orientation <span style="color: #002200;">==</span> <span style="color: #2400d9;">1</span> <span style="color: #002200;">&#41;</span> &nbsp;<span style="color: #11740a; font-style: italic;">// allow landscape</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#40;</span>interfaceOrientation <span style="color: #002200;">==</span> UIInterfaceOrientationLandscapeLeft<span style="color: #002200;">&#41;</span> || <span style="color: #002200;">&#40;</span>interfaceOrientation <span style="color: #002200;">==</span> UIInterfaceOrientationLandscapeRight<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">else</span> <span style="color: #11740a; font-style: italic;">// allow autorotation</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p><br class="spacer_" /><br />
以上代码仅仅使得DetailViewController在特定情况下确定是否允许进行自动旋转。但如果初始的方向不正确的话，它却无能为力。比如，我在RootViewController（它允许任何方向的旋转）处于Landscape方向时，点击第一行（row 0），此时的DetailViewController所呈现的UIView仍然处于Landscape，当然这与我程序的本意当然不符。<br />
<br class="spacer_" /><br />
于是我的问题就变成了怎样强迫UIView旋转到特定方向？我在网上搜索到一种方案，即UIDvice的setOrientation: 方法，不过遗憾的是此方法是私有api，当然我不能接受。于是我又试验了UIApplication中setStatusBarOrientation:方法，该方法果然把状态条旋转到了我需要的方向，不过我的UIView还是处于不正确的方向（以我上一段提到的情况为例）。因为在创建DetailViewController时触发的shouldAutorotateToInterfaceOrientation中（发生在setStatusBarOrientation之前），当时的UIInterfaceOrientation还是为landscape，而我的orientation参数为0，所以返回为NO，因此屏幕并没有旋转。有什么方法能够再触发一次shouldAutorotateToInterfaceOrientation吗？<br />
<br class="spacer_" /><br />
答案是肯定的，见我的代码：<br />
<br class="spacer_" /></p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// trick to retrigger shouldAutorotateToInterfaceOrientation method</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; UIWindow <span style="color: #002200;">*</span>window <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span> keyWindow<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; UIView <span style="color: #002200;">*</span>view <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>window.subviews objectAtIndex<span style="color: #002200;">:</span>0<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>view removeFromSuperview<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>window addSubview<span style="color: #002200;">:</span>view<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p><br class="spacer_" /><br />
在setStatusBarOrientation后，调用以上代码，强行触发了shouldAutorotateToInterfaceOrientation了，此时orientation为0，但interfaceOrientation我已经通过setStatusBarOrientation设置成了UIInterfaceOrientationPortrait，所以会返回YES，直接导致UIView的旋转。（以上代码是我在<a href="http://goodliffe.blogspot.com/2009/12/iphone-forcing-uiview-to-reorientate.html">网上</a>看到的方法）。<br />
<br class="spacer_" /><br />
至此，整个解决方案就比较完满了，代码<a href="http://www.iphone-geek.cn/wp-content/uploads/2011/08/Autorotation.zip">下载</a>。不过请注意我的代码实例仅仅针对一种情况进行了处理（即orientation等于1，即仅仅允许UIView处于landscape时），其他情况依此类推。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%bc%ba%e8%bf%abuiview%e4%bb%a5%e6%9f%90%e7%a7%8d%e6%96%b9%e5%90%91%e6%98%be%e7%a4%ba%e7%9a%84%e7%a7%98%e8%af%80/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>无法正确加载@2x的解决办法</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%97%a0%e6%b3%95%e6%ad%a3%e7%a1%ae%e5%8a%a0%e8%bd%bd2x%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%97%a0%e6%b3%95%e6%ad%a3%e7%a1%ae%e5%8a%a0%e8%bd%bd2x%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95#comments</comments>
		<pubDate>Tue, 19 Jul 2011 06:45:01 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[图形图像]]></category>
		<category><![CDATA[基础]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[UIImage]]></category>
		<category><![CDATA[代码片段]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1177</guid>
		<description><![CDATA[为使用retina显示，我们一般把图片的高分辨率版本存为@2x的形式，但是iOS 4.1以前的版本，如果使用imageWithContentsOfFile是无法保证@2x文件正确加载的。我使用如下方法解决此问题：
123456789101112131415161718192021222324252627// UIImage+Extras.h
@interface UIImage &#40;Extras&#41;

- &#40;id&#41;initWithContentsOfResolutionIndependentFile:&#40;NSString *&#41;path;
+ &#40;UIImage*&#41;imageWithContentsOfResolutionIndependentFile:&#40;NSString *&#41;path;

@end

// UIImage+Extras.m
- &#40;id&#41;initWithContentsOfResolutionIndependentFile:&#40;NSString *&#41;path &#123;
&#160; &#160; if &#40; &#91;&#91;&#91;UIDevice currentDevice&#93; systemVersion&#93; intValue&#93; &#62;= 4 &#38;&#38; &#91;&#91;UIScreen mainScreen&#93; scale&#93; == 2.0 &#41; &#123;
&#160; &#160; &#160; &#160; NSString *path2x = &#91;&#91;path stringByDeletingLastPathComponent&#93; 
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; stringByAppendingPathComponent:&#91;NSString stringWithFormat:@&#34;%@@2x.%@&#34;, 
&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>为使用retina显示，我们一般把图片的高分辨率版本存为@2x的形式，但是iOS 4.1以前的版本，如果使用imageWithContentsOfFile是无法保证@2x文件正确加载的。我使用如下方法解决此问题：</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">// UIImage+Extras.h</span><br />
<span style="color: #a61390;">@interface</span> UIImage <span style="color: #002200;">&#40;</span>Extras<span style="color: #002200;">&#41;</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithContentsOfResolutionIndependentFile<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>path;<br />
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span>UIImage<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>imageWithContentsOfResolutionIndependentFile<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>path;<br />
<br />
<span style="color: #a61390;">@end</span><br />
<br />
<span style="color: #11740a; font-style: italic;">// UIImage+Extras.m</span><br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithContentsOfResolutionIndependentFile<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>path <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIDevice currentDevice<span style="color: #002200;">&#93;</span> systemVersion<span style="color: #002200;">&#93;</span> intValue<span style="color: #002200;">&#93;</span> &gt;<span style="color: #002200;">=</span> 4 <span style="color: #002200;">&amp;&amp;</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIScreen mainScreen<span style="color: #002200;">&#93;</span> scale<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> 2.0 <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>path2x <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>path stringByDeletingLastPathComponent<span style="color: #002200;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stringByAppendingPathComponent<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@@2x.%@&quot;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>path lastPathComponent<span style="color: #002200;">&#93;</span> stringByDeletingPathExtension<span style="color: #002200;">&#93;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>path pathExtension<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/"><span style="color: #400080;">NSFileManager</span></a> defaultManager<span style="color: #002200;">&#93;</span> fileExistsAtPath<span style="color: #002200;">:</span>path2x<span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>self initWithCGImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImage imageWithData<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/"><span style="color: #400080;">NSData</span></a> dataWithContentsOfFile<span style="color: #002200;">:</span>path2x<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> CGImage<span style="color: #002200;">&#93;</span> scale<span style="color: #002200;">:</span>2.0 orientation<span style="color: #002200;">:</span>UIImageOrientationUp<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>self initWithData<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/"><span style="color: #400080;">NSData</span></a> dataWithContentsOfFile<span style="color: #002200;">:</span>path<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span>UIImage<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>imageWithContentsOfResolutionIndependentFile<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>path <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImage alloc<span style="color: #002200;">&#93;</span> initWithContentsOfResolutionIndependentFile<span style="color: #002200;">:</span>path<span style="color: #002200;">&#93;</span> autorelease<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%97%a0%e6%b3%95%e6%ad%a3%e7%a1%ae%e5%8a%a0%e8%bd%bd2x%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>presentModalViewController显示半透明UIView</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/presentmodalviewcontroller%e6%98%be%e7%a4%ba%e5%8d%8a%e9%80%8f%e6%98%8euiview</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/presentmodalviewcontroller%e6%98%be%e7%a4%ba%e5%8d%8a%e9%80%8f%e6%98%8euiview#comments</comments>
		<pubDate>Tue, 05 Jul 2011 05:32:32 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[用户界面]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[代码片段]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1175</guid>
		<description><![CDATA[很多时候我们需要使用presentModalViewController来显示Modal View。如果需要显示半透明的Modal View应该怎么办呢？当然可以自己创建一个半透明的UIView，然后模拟presentModalViewController的动画效果。
不过iOS 4以后的版本再也不需要怎么麻烦了，有一个非常简单的方法，示例如下（这段代码运行于一个View Controller中)：
123456&#160; &#160; UIViewController* transparentView = &#91;&#91;UIViewController alloc&#93; init&#93;;&#160; &#160; &#160; &#160; &#160; &#160; 

&#160; &#160; &#160; &#160;UIViewController* controller = self.view.window.rootViewController;
&#160; &#160; &#160; &#160;transparentView.view.backgroundColor = &#91;UIColor clearColor&#93;;
&#160; &#160; &#160; &#160;controller.modalPresentationStyle = UIModalPresentationCurrentContext; &#160; &#160; &#160; &#160;
&#160; &#160; &#160; &#160;&#91;controller presentModalViewController:transparentView animated:YES&#93;;
其要点就是使用iOS特有的rootViewController来显示Modal View。
]]></description>
			<content:encoded><![CDATA[<p>很多时候我们需要使用presentModalViewController来显示Modal View。如果需要显示半透明的Modal View应该怎么办呢？当然可以自己创建一个半透明的UIView，然后模拟presentModalViewController的动画效果。</p>
<p>不过iOS 4以后的版本再也不需要怎么麻烦了，有一个非常简单的方法，示例如下（这段代码运行于一个View Controller中)：</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; UIViewController<span style="color: #002200;">*</span> transparentView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIViewController alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;UIViewController<span style="color: #002200;">*</span> controller <span style="color: #002200;">=</span> self.view.window.rootViewController;<br />
&nbsp; &nbsp; &nbsp; &nbsp;transparentView.view.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor clearColor<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;controller.modalPresentationStyle <span style="color: #002200;">=</span> UIModalPresentationCurrentContext; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #002200;">&#91;</span>controller presentModalViewController<span style="color: #002200;">:</span>transparentView animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>其要点就是使用iOS特有的rootViewController来显示Modal View。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/presentmodalviewcontroller%e6%98%be%e7%a4%ba%e5%8d%8a%e9%80%8f%e6%98%8euiview/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>不需重新编译而更改app资源内容的简单方法</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e4%b8%8d%e9%9c%80%e9%87%8d%e6%96%b0%e7%bc%96%e8%af%91%e8%80%8c%e6%9b%b4%e6%94%b9app%e8%b5%84%e6%ba%90%e5%86%85%e5%ae%b9%e7%9a%84%e7%ae%80%e5%8d%95%e6%96%b9%e6%b3%95</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e4%b8%8d%e9%9c%80%e9%87%8d%e6%96%b0%e7%bc%96%e8%af%91%e8%80%8c%e6%9b%b4%e6%94%b9app%e8%b5%84%e6%ba%90%e5%86%85%e5%ae%b9%e7%9a%84%e7%ae%80%e5%8d%95%e6%96%b9%e6%b3%95#comments</comments>
		<pubDate>Tue, 24 May 2011 02:36:22 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[基础]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[提示与技巧]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1173</guid>
		<description><![CDATA[有的时候，我们需要把做好的项目以另外的程序名和内容重新打包，当然我们可以使用建立一个新的target的方法，不同的情况用不同的target表示。我一位朋友luckywr分享了一种更为简单的方法，特别适合于只需少量更改了项目的内容（比如，更改程序的图标）。其思路也非常简单，就是在更改内容后使用命令行对app重新进行数字签名，而不需要再次对整个程序进行编译了。
下面是他使用的方法：

codesign -f -vv -s [Identity] [appPath]
Identity 是授权文件，是在keychain里使用的私钥的名字。
比如：codesign -f -vv -s &#8220;luckywr&#8221; /Users/luckywr/Desktop/xxxx.app

在此感谢luckywr朋友。
]]></description>
			<content:encoded><![CDATA[<p>有的时候，我们需要把做好的项目以另外的程序名和内容重新打包，当然我们可以使用建立一个新的target的方法，不同的情况用不同的target表示。我一位朋友<a href="luckywr@gmail.com">luckywr</a>分享了一种更为简单的方法，特别适合于只需少量更改了项目的内容（比如，更改程序的图标）。其思路也非常简单，就是在更改内容后使用命令行对app重新进行数字签名，而不需要再次对整个程序进行编译了。</p>
<p>下面是他使用的方法：</p>
<blockquote>
<p>codesign -f -vv -s [Identity] [appPath]</p>
<p>Identity 是授权文件，是在keychain里使用的私钥的名字。</p>
<p>比如：codesign -f -vv -s &#8220;luckywr&#8221; /Users/luckywr/Desktop/xxxx.app</p>
</blockquote>
<p>在此感谢luckywr朋友。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e4%b8%8d%e9%9c%80%e9%87%8d%e6%96%b0%e7%bc%96%e8%af%91%e8%80%8c%e6%9b%b4%e6%94%b9app%e8%b5%84%e6%ba%90%e5%86%85%e5%ae%b9%e7%9a%84%e7%ae%80%e5%8d%95%e6%96%b9%e6%b3%95/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>分享一小段代码</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%88%86%e4%ba%ab%e4%b8%80%e5%b0%8f%e6%ae%b5%e4%bb%a3%e7%a0%81</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%88%86%e4%ba%ab%e4%b8%80%e5%b0%8f%e6%ae%b5%e4%bb%a3%e7%a0%81#comments</comments>
		<pubDate>Fri, 13 May 2011 06:13:58 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[用户界面]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[提示与技巧]]></category>
		<category><![CDATA[代码片段]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1169</guid>
		<description><![CDATA[我们经常会遇到这种情况，某个按钮太小很难按到，又不想把按钮图片做得太大。我把它作成了一个Class Method，放在了我的Utils类中。
123456789101112131415+&#40;void&#41;resizeTouchableAreaForButton:&#40;UIButton* &#41;button withNewSize:&#40;CGSize&#41;size
&#123;
&#160; &#160; // increase margin around button based on width
&#160; &#160; const CGFloat margin_h = 0.5f * &#40; size.width - button.frame.size.width &#41;;
&#160; &#160; const CGFloat margin_v = 0.5f * &#40; size.height - button.frame.size.height &#41;;
&#160; &#160; 
&#160; &#160; // add margin on all four sides of the button
&#160; &#160; CGRect newFrame = button.frame;
&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>我们经常会遇到这种情况，某个按钮太小很难按到，又不想把按钮图片做得太大。我把它作成了一个Class Method，放在了我的Utils类中。</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>resizeTouchableAreaForButton<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIButton<span style="color: #002200;">*</span> <span style="color: #002200;">&#41;</span>button withNewSize<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGSize<span style="color: #002200;">&#41;</span>size<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// increase margin around button based on width</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">const</span> CGFloat margin_h <span style="color: #002200;">=</span> 0.5f <span style="color: #002200;">*</span> <span style="color: #002200;">&#40;</span> size.width <span style="color: #002200;">-</span> button.frame.size.width <span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">const</span> CGFloat margin_v <span style="color: #002200;">=</span> 0.5f <span style="color: #002200;">*</span> <span style="color: #002200;">&#40;</span> size.height <span style="color: #002200;">-</span> button.frame.size.height <span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// add margin on all four sides of the button</span><br />
&nbsp; &nbsp; CGRect newFrame <span style="color: #002200;">=</span> button.frame;<br />
&nbsp; &nbsp; newFrame.origin.x <span style="color: #002200;">-=</span> margin_h;<br />
&nbsp; &nbsp; newFrame.origin.y <span style="color: #002200;">-=</span> margin_v;<br />
&nbsp; &nbsp; newFrame.size.width &nbsp;<span style="color: #002200;">+=</span> 2.0f <span style="color: #002200;">*</span> margin_h;<br />
&nbsp; &nbsp; newFrame.size.height <span style="color: #002200;">+=</span> 2.0f <span style="color: #002200;">*</span> margin_v;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; button.frame <span style="color: #002200;">=</span> newFrame;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>这段代码把按钮的可按区域扩大到新的尺寸。不过有一个前提是使用UIButton的setImage而不是setBackgroundImage来设置按钮图片。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%88%86%e4%ba%ab%e4%b8%80%e5%b0%8f%e6%ae%b5%e4%bb%a3%e7%a0%81/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>pdf渲染的小窍门</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/pdf%e6%b8%b2%e6%9f%93%e7%9a%84%e5%b0%8f%e7%aa%8d%e9%97%a8</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/pdf%e6%b8%b2%e6%9f%93%e7%9a%84%e5%b0%8f%e7%aa%8d%e9%97%a8#comments</comments>
		<pubDate>Thu, 21 Apr 2011 04:10:45 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[图形图像]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[Core Graphics]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[代码片段]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1164</guid>
		<description><![CDATA[ ]]></description>
			<content:encoded><![CDATA[<p>我们都知道，在iPhone/iPad显示pdf的基本方法有两个，一个是使用UIWebView直接加载pdf文件，另一个是使用Core Graphics进行渲染（姑且称之为CGPDF方法）。UIWebView的方法是简单，只需加载pdf，其他诸如放大翻页等问题通通交给UIWebView去头痛吧。但其缺点是性能较慢，功能有限，比如要实现搜索，添加笔记等功能就比较难。而使用CGPDF方法，功能就没有限制（虽然pdf解析方面，苹果提供的文档实在有限），使用Core Graphics进行渲染，性能上也比UIWebView要提高许多，只不过翻页，放大缩小等功能都需要自己实现。<br class="spacer_" /><br />
<span id="more-1164"></span><br />
有关pdf放大缩小，翻页等功能可以使用UIScrollView实现，不在本文讨论的范围之内。笔者在项目中使用了CGPDF的过程中，曾遇到两个小问题，因此，在这里总结一下：<br />
<br class="spacer_" /></p>
<h2>1. 页面放大后变得不清晰<br />
<br class="spacer_" /></h2>
<p>先看看我程序中的渲染代码，可以放在- (void)drawRect:(CGRect)rect 或者 -(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context 中：<br class="spacer_" /></p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>drawRect<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGRect<span style="color: #002200;">&#41;</span>rect<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; CGContextRef context <span style="color: #002200;">=</span> UIGraphicsGetCurrentContext<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// fill in the white background for pdf page</span><br />
&nbsp; &nbsp; CGContextSetRGBFillColor<span style="color: #002200;">&#40;</span> context, 1.0, 1.0, 1.0, 1.0 <span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextFillRect<span style="color: #002200;">&#40;</span> context, CGContextGetClipBoundingBox<span style="color: #002200;">&#40;</span> context <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextSaveGState<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Flip the context so that the PDF page is rendered</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// right side up.</span><br />
&nbsp; &nbsp; CGContextTranslateCTM<span style="color: #002200;">&#40;</span> context, 0.0, self.bounds.size.height <span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextScaleCTM<span style="color: #002200;">&#40;</span> context, 1.0, <span style="color: #002200;">-</span>1.0 <span style="color: #002200;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Scale the context so that the PDF page is rendered</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// at the correct size for the zoom level.</span><br />
&nbsp; &nbsp; CGAffineTransform pdfXfm <span style="color: #002200;">=</span><br />
&nbsp; &nbsp; CGPDFPageGetDrawingTransform<span style="color: #002200;">&#40;</span> _page.page, kCGPDFMediaBox, self.bounds, 0, <span style="color: #a61390;">true</span> <span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextConcatCTM<span style="color: #002200;">&#40;</span> context, pdfXfm <span style="color: #002200;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; CGContextSetInterpolationQuality<span style="color: #002200;">&#40;</span>context, kCGInterpolationHigh<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextSetRenderingIntent<span style="color: #002200;">&#40;</span>context, kCGRenderingIntentDefault<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextDrawPDFPage<span style="color: #002200;">&#40;</span> context, _page.page <span style="color: #002200;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; CGContextRestoreGState<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p><br class="spacer_" /><br />
简单地说，这段代码就是使用Core Graphics进行pdf的渲染，可是我的pdf放大后为什么不清晰呢？先看看放大pdf后可以使其清晰的部分代码吧：<br class="spacer_" /></p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithPdfPage<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>PDFPage<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>page<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0, 0, page.size.width, page.size.height<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CATiledLayer<span style="color: #002200;">*</span> layer <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>CATiledLayer <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>self layer<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; layer.levelsOfDetail <span style="color: #002200;">=</span> <span style="color: #2400d9;">4</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; layer.levelsOfDetailBias <span style="color: #002200;">=</span> <span style="color: #2400d9;">4</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; layer.tileSize <span style="color: #002200;">=</span> CGSizeMake<span style="color: #002200;">&#40;</span>1024.0, 1024.0<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> self;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">Class</span><span style="color: #002200;">&#41;</span>layerClass<br />
<span style="color: #002200;">&#123;</span><br />
<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>CATiledLayer class<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p><br class="spacer_" /><br />
其秘诀就在CATiledLayer，简单地说就是CATiledLayer将不同等级的tiles（拼贴）缓存起来，而CGContextDrawPDFPage则根据最合适的放大等级将pdf渲染出来。<br class="spacer_" /></p>
<p>根据文档CATiledLayer可以更高效，高质量地渲染pdf文档，但我则遇到了第二个问题。<br />
<br class="spacer_" /></p>
<h2>2. 页面渲染速度慢，而且呈块状渲染<br />
<br class="spacer_" /></h2>
<p>简而言之就是pdf页面一块一块地慢慢渲染出来，效果非常不好。这是怎么回事？经过一番研究发现是CATiledLayer的动画效果在作怪。每个Tile的渲染据说都有0.25s的动画时间，其结果就是pdf文档一块一块地出现了。要怎样解决这个问题呢？最为直接的方法就是把0.25s的动画时间直接设置为0。下面是代码（采用继承CATiledLayer的方法）：<br class="spacer_" /></p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a61390;">@interface</span> FastCATiledLayer <span style="color: #002200;">:</span> CATiledLayer<br />
<span style="color: #a61390;">@end</span><br />
<br />
<span style="color: #a61390;">@implementation</span> FastCATiledLayer<br />
<span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span>CFTimeInterval<span style="color: #002200;">&#41;</span>fadeDuration <br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #2400d9;">0.0</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">Class</span><span style="color: #002200;">&#41;</span>layerClass <br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>FastCATiledLayer class<span style="color: #002200;">&#93;</span>; &nbsp; <br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>initWithPdfPage<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>PDFPage<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>page <br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0, 0, page.size.width, page.size.height<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; FastCATiledLayer<span style="color: #002200;">*</span> layer <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>FastCATiledLayer <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>self layer<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; layer.levelsOfDetail <span style="color: #002200;">=</span> <span style="color: #2400d9;">4</span>;<br />
&nbsp; &nbsp; layer.levelsOfDetailBias <span style="color: #002200;">=</span> <span style="color: #2400d9;">4</span>;<br />
&nbsp; &nbsp; layer.tileSize <span style="color: #002200;">=</span> CGSizeMake<span style="color: #002200;">&#40;</span>1024.0, 1024.0<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> self;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<h5>注:PDFPage是我自己的一个类。</h5>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/pdf%e6%b8%b2%e6%9f%93%e7%9a%84%e5%b0%8f%e7%aa%8d%e9%97%a8/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cocos2d实现简单动画</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/cocos2d%e5%ae%9e%e7%8e%b0%e7%ae%80%e5%8d%95%e5%8a%a8%e7%94%bb</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/cocos2d%e5%ae%9e%e7%8e%b0%e7%ae%80%e5%8d%95%e5%8a%a8%e7%94%bb#comments</comments>
		<pubDate>Fri, 15 Apr 2011 03:33:15 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[图形图像]]></category>
		<category><![CDATA[游戏]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[OpenGL ES]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1158</guid>
		<description><![CDATA[最近实在很忙，没有时间写整篇文章，就分享一下一些简单的实例吧。
首先介绍一篇博客文章：cocos2d HOWTO系列之：如何创建帧动画。我初学cocos2d时就发现这篇文章，不过里面的一些内容已经过时了，所以自己又写了一个动画的例子。
我把要点说一下：

制作动画需要的一系列动画图片（比如png文件）。要制作动画png，可根据上面介绍的文章使用Adobe Flash将fla转换为png。也可以使用一些免费软件，将swf转换为png。这里有一些软件：SpriteSheetCreator，SWFSheet，SWFToPNG。大家可以网上搜索一下。
生成png动画系列后，要将其整合成一个png（也就是所谓的sprite sheet）。这里使用的软件就是Zwoptex。使用此软件生成一个png和一个plist，plist记录了每个sprite的x，y，高，宽数据。Cocos2d支持Zwoptex生成的plist格式。不过遗憾的是最近Zwoptex开始收费了。这里提供以前的一个版本，也可以满足我们的要求。Zwoptex-0.4b10.app下载 。
我的程序就是播放一个电扇的动画，按一下就进行动画，再按一下动画就停止。我是修改了HelloWorld程序，添加了一个Object类进行动画处理。唯一要说明的是addSpriteFramesWithFile中要使用的路径是相对路径，我开始一直遇到问题就是因为使用了绝对路径。

源代码下载
]]></description>
			<content:encoded><![CDATA[<p>最近实在很忙，没有时间写整篇文章，就分享一下一些简单的实例吧。</p>
<p>首先介绍一篇博客文章：<a href="http://dualface.qeeplay.com/index.php/archives/406">cocos2d HOWTO系列之：如何创建帧动画</a>。我初学cocos2d时就发现这篇文章，不过里面的一些内容已经过时了，所以自己又写了一个动画的例子。</p>
<p>我把要点说一下：</p>
<ol>
<li>制作动画需要的一系列动画图片（比如png文件）。要制作动画png，可根据上面介绍的文章使用Adobe Flash将fla转换为png。也可以使用一些免费软件，将swf转换为png。这里有一些软件：SpriteSheetCreator，SWFSheet，SWFToPNG。大家可以网上搜索一下。</li>
<li>生成png动画系列后，要将其整合成一个png（也就是所谓的sprite sheet）。这里使用的软件就是Zwoptex。使用此软件生成一个png和一个plist，plist记录了每个sprite的x，y，高，宽数据。Cocos2d支持Zwoptex生成的plist格式。不过遗憾的是最近Zwoptex开始收费了。这里提供以前的一个版本，也可以满足我们的要求。<a href="http://www.iphone-geek.cn/wp-content/uploads/2011/04/Zwoptex-0.4b10.app.zip">Zwoptex-0.4b10.app下载</a> 。</li>
<li>我的程序就是播放一个电扇的动画，按一下就进行动画，再按一下动画就停止。我是修改了HelloWorld程序，添加了一个Object类进行动画处理。唯一要说明的是addSpriteFramesWithFile中要使用的路径是相对路径，我开始一直遇到问题就是因为使用了绝对路径。</li>
</ol>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2011/04/animation.zip">源代码下载</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/cocos2d%e5%ae%9e%e7%8e%b0%e7%ae%80%e5%8d%95%e5%8a%a8%e7%94%bb/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Xcode 4闲谈</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/xcode-4</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/xcode-4#comments</comments>
		<pubDate>Thu, 31 Mar 2011 04:47:02 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[基础]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1150</guid>
		<description><![CDATA[Xcode 4终于千呼万唤发布了，诚然它有太多亮点，不过目前还是感觉不够稳定，还有很多功能都不会用。举个简单的例子，在Ｘcode 3下，使用Analyze时有非常多的误报，但Ｘcode 4似乎又走了另一个极端，几乎没有什么报告。我有一个程序明显有memory leak（因为我安装了状态条可以显示内存的软件），但Analyze的结果是没有potential leak，而且使用Instrument也没有发现任何leak，不知是不是我还不太会用。
另外，还有一些以前比较熟练的事情在Xcode 4下，都不会做了。比如， 当程序出现EXC_BAD_ACCESS时添加NSZombieEnabled环境变量开始都找不到地方。最后终于找到了，在：
Product -&#62; Edit Scheme&#8230;

4月1日更新：
今天发现一个有趣的现象。突然发现以前为Xcode项目添加静态库子项目的方法不再适用，添加的项目文件只是一个文件而已。后来经过研究才发现是因为Xcode打开了另外一个项目的缘故。关掉另一个Xcode后，问题解决。
]]></description>
			<content:encoded><![CDATA[<p>Xcode 4终于千呼万唤发布了，诚然它有太多亮点，不过目前还是感觉不够稳定，还有很多功能都不会用。举个简单的例子，在Ｘcode 3下，使用Analyze时有非常多的误报，但Ｘcode 4似乎又走了另一个极端，几乎没有什么报告。我有一个程序明显有memory leak（因为我安装了状态条可以显示内存的软件），但Analyze的结果是没有potential leak，而且使用Instrument也没有发现任何leak，不知是不是我还不太会用。<br class="spacer_" /><br />
另外，还有一些以前比较熟练的事情在Xcode 4下，都不会做了。比如， 当程序出现EXC_BAD_ACCESS时添加NSZombieEnabled环境变量开始都找不到地方。最后终于找到了，在：</p>
<blockquote><p>Product -&gt; Edit Scheme&#8230;</p></blockquote>
<p><br class="spacer_" /><br />
<strong>4月1日更新：</strong><br />
今天发现一个有趣的现象。突然发现以前为Xcode项目添加静态库子项目的方法不再适用，添加的项目文件只是一个文件而已。后来经过研究才发现是因为Xcode打开了另外一个项目的缘故。关掉另一个Xcode后，问题解决。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/xcode-4/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

