<?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/tag/%e4%bb%a3%e7%a0%81%e7%89%87%e6%ae%b5/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>强迫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>分享一小段代码</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>检测当前设备是否为iPad</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%a3%80%e6%b5%8b%e5%bd%93%e5%89%8d%e8%ae%be%e5%a4%87%e6%98%af%e5%90%a6%e4%b8%baipad</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%a3%80%e6%b5%8b%e5%bd%93%e5%89%8d%e8%ae%be%e5%a4%87%e6%98%af%e5%90%a6%e4%b8%baipad#comments</comments>
		<pubDate>Fri, 07 Jan 2011 06:42:13 +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=1100</guid>
		<description><![CDATA[今天编写一个程序时需要检测当前设备是否为iPad，正好用到开源Cocos2d库，发现里面是使用下面代码段进行检测的：
&#160;

12345&#160; &#160; if &#40;UI_USER_INTERFACE_IDIOM&#40;&#41; == UIUserInterfaceIdiomPad&#41; &#123;
&#160; &#160; &#160; &#160; &#91;_pages addObject:@&#34;page1-ipad.jpg&#34;&#93;;
&#160; &#160; &#125; else &#123;
&#160; &#160; &#160; &#160; &#91;_pages addObject:@&#34;page2.jpg&#34;&#93;;
&#160; &#160; &#125;

&#038;nbsp
]]></description>
			<content:encoded><![CDATA[<p>今天编写一个程序时需要检测当前设备是否为iPad，正好用到开源Cocos2d库，发现里面是使用下面代码段进行检测的：</p>
<p>&nbsp;</p>
<blockquote>
<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; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>UI_USER_INTERFACE_IDIOM<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">==</span> UIUserInterfaceIdiomPad<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>_pages addObject<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;page1-ipad.jpg&quot;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>_pages addObject<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;page2.jpg&quot;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
</blockquote>
<p>&#038;nbsp</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%a3%80%e6%b5%8b%e5%bd%93%e5%89%8d%e8%ae%be%e5%a4%87%e6%98%af%e5%90%a6%e4%b8%baipad/feed</wfw:commentRss>
		<slash:comments>1</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%e6%ae%b5%e4%bb%a3%e7%a0%81%e5%b8%ae%e5%8a%a9%e8%bf%9b%e8%a1%8c%e8%b0%83%e8%af%95</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%88%86%e4%ba%ab%e4%b8%80%e6%ae%b5%e4%bb%a3%e7%a0%81%e5%b8%ae%e5%8a%a9%e8%bf%9b%e8%a1%8c%e8%b0%83%e8%af%95#comments</comments>
		<pubDate>Wed, 01 Dec 2010 06:24:35 +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=1094</guid>
		<description><![CDATA[有时程序崩溃根本不知错误发生在什么地方。比如程序出现EXEC_BAD_ACCESS的时候，虽然大部分情况使用设定NSZombieEnabled环境变量可以帮助你找到问题的所在，但少数情况下，即使设定了NSZombieEnabled环境变量，还是不知道程序崩溃在什么地方。那么就需要使用下列代码进行帮助了：
123456#ifdef _FOR_DEBUG_
-&#40;BOOL&#41; respondsToSelector:&#40;SEL&#41;aSelector &#123;
&#160; &#160; printf&#40;&#34;SELECTOR: %s\n&#34;, &#91;NSStringFromSelector&#40;aSelector&#41; UTF8String&#93;&#41;;
&#160; &#160; return &#91;super respondsToSelector:aSelector&#93;;
&#125;
#endif
你需要在每个object的.m或者.mm文件中加入上面代码，并且在other c flags中加入-D _FOR_DEBUG_（记住请只在Debug Configuration下加入此标记）。这样当你程序崩溃时，Xcode的console上就会准确地记录了最后运行的object的方法。
]]></description>
			<content:encoded><![CDATA[<p>有时程序崩溃根本不知错误发生在什么地方。比如程序出现EXEC_BAD_ACCESS的时候，虽然大部分情况使用设定NSZombieEnabled环境变量可以帮助你找到问题的所在，但少数情况下，即使设定了NSZombieEnabled环境变量，还是不知道程序崩溃在什么地方。那么就需要使用下列代码进行帮助了：</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"><span style="color: #6e371a;">#ifdef _FOR_DEBUG_</span><br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span> respondsToSelector<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">SEL</span><span style="color: #002200;">&#41;</span>aSelector <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #a61390;">printf</span></a><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;SELECTOR: %s<span style="color: #2400d9;">\n</span>&quot;</span>, <span style="color: #002200;">&#91;</span>NSStringFromSelector<span style="color: #002200;">&#40;</span>aSelector<span style="color: #002200;">&#41;</span> UTF8String<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span>super respondsToSelector<span style="color: #002200;">:</span>aSelector<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<span style="color: #6e371a;">#endif</span></div></td></tr></tbody></table></div>
<p>你需要在每个object的.m或者.mm文件中加入上面代码，并且在other c flags中加入-D _FOR_DEBUG_（记住请只在Debug Configuration下加入此标记）。这样当你程序崩溃时，Xcode的console上就会准确地记录了最后运行的object的方法。</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%e6%ae%b5%e4%bb%a3%e7%a0%81%e5%b8%ae%e5%8a%a9%e8%bf%9b%e8%a1%8c%e8%b0%83%e8%af%95/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>程序中读取可用内存</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e7%a8%8b%e5%ba%8f%e4%b8%ad%e8%af%bb%e5%8f%96%e5%8f%af%e7%94%a8%e5%86%85%e5%ad%98</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e7%a8%8b%e5%ba%8f%e4%b8%ad%e8%af%bb%e5%8f%96%e5%8f%af%e7%94%a8%e5%86%85%e5%ad%98#comments</comments>
		<pubDate>Tue, 23 Nov 2010 08:33:27 +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=1092</guid>
		<description><![CDATA[iPhone/iPad的内存十分紧张，所以有时进行调试时可能需要读取当前可用内存。其实挺简单，见下列代码：
1234567891011121314151617181920#import &#60;mach/mach.h&#62;
#import &#60;mach/mach_host.h&#62;

@implementation Utils

+ &#40;double&#41;getAvailableMemory
&#123;
&#160; &#160; vm_statistics_data_t vmStats;
&#160; &#160; mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
&#160; &#160; kern_return_t kernReturn = host_statistics&#40;mach_host_self&#40;&#41;, HOST_VM_INFO, &#40;host_info_t&#41;&#38;vmStats, &#38;infoCount&#41;;
&#160; &#160; 
&#160; &#160; if &#40;kernReturn != KERN_SUCCESS&#41;
&#160; &#160; &#123;
&#160; &#160; &#160; &#160; return NSNotFound;
&#160; &#160; &#125;
&#160; &#160; 
&#160; &#160; return &#40;vm_page_size * vmStats.free_count&#41;;
&#125;

end
使用方法更简单，比如：
1NSLog&#40;@&#34;Available memory (KB) = &#160;%f&#34;,&#91;Utils getAvailableMemory&#93;&#41;;
]]></description>
			<content:encoded><![CDATA[<p>iPhone/iPad的内存十分紧张，所以有时进行调试时可能需要读取当前可用内存。其实挺简单，见下列代码：</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 /></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: #6e371a;">#import &lt;mach/mach.h&gt;</span><br />
<span style="color: #6e371a;">#import &lt;mach/mach_host.h&gt;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> Utils<br />
<br />
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">double</span><span style="color: #002200;">&#41;</span>getAvailableMemory<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; vm_statistics_data_t vmStats;<br />
&nbsp; &nbsp; mach_msg_type_number_t infoCount <span style="color: #002200;">=</span> HOST_VM_INFO_COUNT;<br />
&nbsp; &nbsp; kern_return_t kernReturn <span style="color: #002200;">=</span> host_statistics<span style="color: #002200;">&#40;</span>mach_host_self<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>, HOST_VM_INFO, <span style="color: #002200;">&#40;</span>host_info_t<span style="color: #002200;">&#41;</span><span style="color: #002200;">&amp;</span>vmStats, <span style="color: #002200;">&amp;</span>infoCount<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>kernReturn <span style="color: #002200;">!=</span> KERN_SUCCESS<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> NSNotFound;<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;">&#40;</span>vm_page_size <span style="color: #002200;">*</span> vmStats.free_count<span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
end</div></td></tr></tbody></table></div>
<p>使用方法更简单，比如：</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 /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Available memory (KB) = &nbsp;%f&quot;</span>,<span style="color: #002200;">&#91;</span>Utils getAvailableMemory<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;</div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e7%a8%8b%e5%ba%8f%e4%b8%ad%e8%af%bb%e5%8f%96%e5%8f%af%e7%94%a8%e5%86%85%e5%ad%98/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>怎样使UISearchBar背景透明</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%80%8e%e6%a0%b7%e4%bd%bfuisearchbar%e8%83%8c%e6%99%af%e9%80%8f%e6%98%8e</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%80%8e%e6%a0%b7%e4%bd%bfuisearchbar%e8%83%8c%e6%99%af%e9%80%8f%e6%98%8e#comments</comments>
		<pubDate>Tue, 14 Sep 2010 10:51:09 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[用户界面]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[UISearchBar]]></category>
		<category><![CDATA[代码片段]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1072</guid>
		<description><![CDATA[在使用UISearchBar时，将背景色设定为clearColor，或者将translucent设为YES，都不能使背景透明，经过一番研究，发现了一种超级简单和实用的方法：
1&#91;&#91;searchbar.subviews objectAtIndex:0&#93;removeFromSuperview&#93;;
背景完全消除了，只剩下搜索框本身了。
]]></description>
			<content:encoded><![CDATA[<p>在使用UISearchBar时，将背景色设定为clearColor，或者将translucent设为YES，都不能使背景透明，经过一番研究，发现了一种超级简单和实用的方法：</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 /></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;">&#91;</span><span style="color: #002200;">&#91;</span>searchbar.subviews objectAtIndex<span style="color: #002200;">:</span>0<span style="color: #002200;">&#93;</span>removeFromSuperview<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>背景完全消除了，只剩下搜索框本身了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%80%8e%e6%a0%b7%e4%bd%bfuisearchbar%e8%83%8c%e6%99%af%e9%80%8f%e6%98%8e/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

