<?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/%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>强迫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>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>检查UIWebView上touch的最简单的方法</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%a3%80%e6%9f%a5uiwebview%e4%b8%8atouch%e7%9a%84%e6%9c%80%e7%ae%80%e5%8d%95%e7%9a%84%e6%96%b9%e6%b3%95</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%a3%80%e6%9f%a5uiwebview%e4%b8%8atouch%e7%9a%84%e6%9c%80%e7%ae%80%e5%8d%95%e7%9a%84%e6%96%b9%e6%b3%95#comments</comments>
		<pubDate>Thu, 10 Mar 2011 02:09:29 +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=1138</guid>
		<description><![CDATA[我有一个程序需要检测UIWebView是否有touch动作，不幸得很，UIWebView上的touchesBegan等事件无法被检测。在网上查了一下，有许多解决方法，比如在UIWebView上再加一个透明的UIView，重置UIWindow的sendEvent或重置UIWebView的hitest方法等等，要么就是方案不太完美，要么就是太过复杂，经过实验我使用的这种方法最为简单（否则我也没有时间写在这里了），当然我只要求检测UIWebView上有touch动作即可。我的方法是使用UITapGestureRecognizer。关键的地方有两点，请看我的代码（我的代码是在一个UIViewController中):

12345&#160; &#160; UITapGestureRecognizer* singleTap = &#91;&#91;UITapGestureRecognizer alloc&#93; initWithTarget:self action:@selector&#40;handleSingleTap:&#41;&#93;;
&#160; &#160; &#91;self.view addGestureRecognizer:singleTap&#93;;
&#160; &#160; singleTap.delegate = self;
&#160; &#160; singleTap.cancelsTouchesInView = NO;
&#160; &#160; &#91;singleTap release&#93;;
第三行是第一个关键的地方，就是必须设置UITapGuestureRecognizer的delegate（一般我们直接使用initＷithＴarget，无需设置其delegate）。
第二个关键的地方是在下列delegate方法return YES。

1234- &#40;BOOL&#41;gestureRecognizer:&#40;UIGestureRecognizer *&#41;gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:&#40;UIGestureRecognizer *&#41;otherGestureRecognizer
&#123;
&#160; &#160; return YES;
&#125;
做到这两点，你的UIWebView就可以响应touch事件了，你可以使用不同的UIGestureRecognizer来满足你不同的要求等。(handleSingleTap方法请自行补上）。
]]></description>
			<content:encoded><![CDATA[<p>我有一个程序需要检测UIWebView是否有touch动作，不幸得很，UIWebView上的touchesBegan等事件无法被检测。在网上查了一下，有许多解决方法，比如在UIWebView上再加一个透明的UIView，重置UIWindow的sendEvent或重置UIWebView的hitest方法等等，要么就是方案不太完美，要么就是太过复杂，经过实验我使用的这种方法最为简单（否则我也没有时间写在这里了），当然我只要求检测UIWebView上有touch动作即可。我的方法是使用UITapGestureRecognizer。关键的地方有两点，请看我的代码（我的代码是在一个UIViewController中):<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; UITapGestureRecognizer<span style="color: #002200;">*</span> singleTap <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UITapGestureRecognizer alloc<span style="color: #002200;">&#93;</span> initWithTarget<span style="color: #002200;">:</span>self action<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>handleSingleTap<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.view addGestureRecognizer<span style="color: #002200;">:</span>singleTap<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; singleTap.delegate <span style="color: #002200;">=</span> self;<br />
&nbsp; &nbsp; singleTap.cancelsTouchesInView <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>singleTap release<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p><br class="spacer_" />第三行是第一个关键的地方，就是必须设置UITapGuestureRecognizer的delegate（一般我们直接使用initＷithＴarget，无需设置其delegate）。<br />
<br class="spacer_" />第二个关键的地方是在下列delegate方法return YES。<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 /></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;">BOOL</span><span style="color: #002200;">&#41;</span>gestureRecognizer<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIGestureRecognizer <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIGestureRecognizer <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>otherGestureRecognizer<br />
<span style="color: #002200;">&#123;</span><br />
&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_" />做到这两点，你的UIWebView就可以响应touch事件了，你可以使用不同的UIGestureRecognizer来满足你不同的要求等。(handleSingleTap方法请自行补上）。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%a3%80%e6%9f%a5uiwebview%e4%b8%8atouch%e7%9a%84%e6%9c%80%e7%ae%80%e5%8d%95%e7%9a%84%e6%96%b9%e6%b3%95/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>NSOperation和NSURLConnection</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/nsoperation%e5%92%8cnsurlconnection</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/nsoperation%e5%92%8cnsurlconnection#comments</comments>
		<pubDate>Wed, 23 Feb 2011 05:48: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=1128</guid>
		<description><![CDATA[最近一个客户向我汇报了一个程序的问题。经过分析发现问题是NSURLConnection没有正常工作。记得以前测试时没有问题啊。后来上网查到原来在iOS 4.0以后，NSURLConnection无法在NSOperation中正常运行，换句话说，NSURLConnection只能运行于主线程。解决方法其实倒是蛮简单（比如我的程序在download中）：
123456789101112-&#40;void&#41;download
&#123;
&#160; &#160; // NSURLConnectionn won't work if it's not in the main thread
&#160; &#160; if &#40;!&#91;NSThread isMainThread&#93;&#41;
&#160; &#160; &#123;
&#160; &#160; &#160; &#160; &#91;self performSelectorOnMainThread:@selector&#40;download&#41; withObject:nil waitUntilDone:NO&#93;;
&#160; &#160; &#160; &#160; return;
&#160; &#160; &#125;
&#160; &#160; 
&#160; &#160; NSURLRequest *request = &#91;NSURLRequest requestWithURL:&#91;NSURL URLWithString:_urlString&#93;&#93;;
&#160; &#160; _connection = &#91;&#91;NSURLConnection alloc&#93; initWithRequest:request delegate:self&#93;;&#160; &#160; &#160; 
&#125;
]]></description>
			<content:encoded><![CDATA[<p>最近一个客户向我汇报了一个程序的问题。经过分析发现问题是NSURLConnection没有正常工作。记得以前测试时没有问题啊。后来上网查到原来在iOS 4.0以后，NSURLConnection无法在NSOperation中正常运行，换句话说，NSURLConnection只能运行于主线程。解决方法其实倒是蛮简单（比如我的程序在download中）：</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 /></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>download<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// NSURLConnectionn won't work if it's not in the main thread</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSThread_Class/"><span style="color: #400080;">NSThread</span></a> isMainThread<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self performSelectorOnMainThread<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>download<span style="color: #002200;">&#41;</span> withObject<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span> waitUntilDone<span style="color: #002200;">:</span><span style="color: #a61390;">NO</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/"><span style="color: #400080;">NSURLRequest</span></a> <span style="color: #002200;">*</span>request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/"><span style="color: #400080;">NSURLRequest</span></a> requestWithURL<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/"><span style="color: #400080;">NSURL</span></a> URLWithString<span style="color: #002200;">:</span>_urlString<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; _connection <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/"><span style="color: #400080;">NSURLConnection</span></a> alloc<span style="color: #002200;">&#93;</span> initWithRequest<span style="color: #002200;">:</span>request delegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;&nbsp; &nbsp; &nbsp; <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/nsoperation%e5%92%8cnsurlconnection/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CALayer简单教程</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/calayer%e7%ae%80%e5%8d%95%e6%95%99%e7%a8%8b</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/calayer%e7%ae%80%e5%8d%95%e6%95%99%e7%a8%8b#comments</comments>
		<pubDate>Tue, 18 Jan 2011 07:08:34 +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=1104</guid>
		<description><![CDATA[前一阵子读到一篇介绍CALayer（这里简单地称其为层）的教程，比较简单易懂，适合初学者，我在这里就不完全翻译了，只是把要点说明一下。

首先要说的是CALayers 是屏幕上的一个具有可见内容的矩形区域，每个UIView都有一个根CALayer，其所有的绘制（视觉效果）都是在这个layer上进行的。（译者注：为验证这点，我写下了如下代码：
12345678910UILabel* lable = &#91;&#91;UILabel alloc&#93;initWithFrame:CGRectMake&#40;0, 0, 100, 30&#41;&#93;;
lable.text = @&#34;test&#34;;
&#91;self.view addSubview: lable&#93;;
lable.backgroundColor = &#91;UIColor clearColor&#93;;
&#91;lable release&#93;;

// 设定CALayer
self.view.layer.backgroundColor =&#91;UIColor orangeColor&#93;.CGColor;
self.view.layer.cornerRadius =20.0;
self.view.layer.frame = CGRectInset&#40;self.view.layer.frame, 20, 20&#41;;
请注意，我创建的UILable始终随着UIView的根CALayer的缩放而改变位置。）
其次，CALayer的可以影响其外观的特性有：

层的大小尺寸
背景色
内容（比如图像或是使用Core Graphics绘制的内容）
是否使用圆角
是否使用阴影
等等

需要说明的是CALayer的大部分属性都可以用来实现动画效果。
另外，你可以直接使用CALayer，也可以使用其子类，如CAGradientLayer，CATextLayer， CAShapeLayer等等。
示例
首先在Xcode中创建一个View-based App，CALayer是属于QuartzCore framework的，所以需要引入QuartzCore framework，另外在程序中包括QuartzCore.h。
第一个例子是创建一个带圆角的层，在你的ViewController中的ViewDidLoad中加入下面代码：
1234567// Import QuartzCore.h at the top of the file
#import &#60;QuartzCore/QuartzCore.h&#62;

// Uncomment viewDidLoad and add the following lines
self.view.layer.backgroundColor =&#91;UIColor orangeColor&#93;.CGColor;
self.view.layer.cornerRadius =20.0;
self.view.layer.frame = CGRectInset&#40;self.view.layer.frame, 20, 20&#41;;
结果如下：

然后添加一个带阴影效果的子层，加入下列代码：
12345678CALayer *sublayer = [...]]]></description>
			<content:encoded><![CDATA[<p>前一阵子读到一篇介绍CALayer（这里简单地称其为层）的教程，比较简单易懂，适合初学者，我在这里就不完全翻译了，只是把要点说明一下。</p>
<p><span id="more-1104"></span></p>
<p>首先要说的是CALayers 是屏幕上的一个具有可见内容的矩形区域，每个UIView都有一个根CALayer，其所有的绘制（视觉效果）都是在这个layer上进行的。（译者注：为验证这点，我写下了如下代码：</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 /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">UILabel<span style="color: #002200;">*</span> lable <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UILabel alloc<span style="color: #002200;">&#93;</span>initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span>0, 0, 100, 30<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;<br />
lable.text <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;test&quot;</span>;<br />
<span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span> lable<span style="color: #002200;">&#93;</span>;<br />
lable.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor clearColor<span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#91;</span>lable release<span style="color: #002200;">&#93;</span>;<br />
<br />
<span style="color: #11740a; font-style: italic;">// 设定CALayer</span><br />
self.view.layer.backgroundColor <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span>UIColor orangeColor<span style="color: #002200;">&#93;</span>.CGColor;<br />
self.view.layer.cornerRadius <span style="color: #002200;">=</span><span style="color: #2400d9;">20.0</span>;<br />
self.view.layer.frame <span style="color: #002200;">=</span> CGRectInset<span style="color: #002200;">&#40;</span>self.view.layer.frame, 20, 20<span style="color: #002200;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>请注意，我创建的UILable始终随着UIView的根CALayer的缩放而改变位置。）</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-weight: inherit; font-style: inherit; font-size: 13px; font-family: inherit; vertical-align: baseline; line-height: 1.4em; margin: 0px; border: 0px initial initial;">其次，CALayer的可以影响其外观的特性有：</p>
<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 40px; outline-width: 0px; outline-style: initial; outline-color: initial; font-weight: inherit; font-style: inherit; font-size: 13px; font-family: inherit; vertical-align: baseline; list-style-type: none; list-style-position: initial; list-style-image: initial; padding: 0px; border: 0px initial initial;">
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-weight: inherit; font-style: inherit; font-size: 13px; font-family: inherit; vertical-align: baseline; display: list-item; line-height: 1.4em; list-style-type: disc; padding: 0px; border: 0px initial initial;">层的大小尺寸</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-weight: inherit; font-style: inherit; font-size: 13px; font-family: inherit; vertical-align: baseline; display: list-item; line-height: 1.4em; list-style-type: disc; padding: 0px; border: 0px initial initial;">背景色</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-weight: inherit; font-style: inherit; font-size: 13px; font-family: inherit; vertical-align: baseline; display: list-item; line-height: 1.4em; list-style-type: disc; padding: 0px; border: 0px initial initial;">内容（比如图像或是使用<a style="outline-width: 0px; outline-style: initial; outline-color: initial; font-weight: inherit; font-style: inherit; font-size: 13px; font-family: inherit; vertical-align: baseline; color: #006837; padding: 0px; margin: 0px; border: 0px initial initial;" href="http://www.raywenderlich.com/tag/core-graphics">Core Graphics</a>绘制的内容）</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-weight: inherit; font-style: inherit; font-size: 13px; font-family: inherit; vertical-align: baseline; display: list-item; line-height: 1.4em; list-style-type: disc; padding: 0px; border: 0px initial initial;">是否使用圆角</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-weight: inherit; font-style: inherit; font-size: 13px; font-family: inherit; vertical-align: baseline; display: list-item; line-height: 1.4em; list-style-type: disc; padding: 0px; border: 0px initial initial;">是否使用阴影</li>
<li style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-weight: inherit; font-style: inherit; font-size: 13px; font-family: inherit; vertical-align: baseline; display: list-item; line-height: 1.4em; list-style-type: disc; padding: 0px; border: 0px initial initial;">等等</li>
</ul>
<p>需要说明的是CALayer的大部分属性都可以用来实现动画效果。</p>
<p>另外，你可以直接使用CALayer，也可以使用其子类，如CAGradientLayer，CATextLayer， CAShapeLayer等等。</p>
<h2>示例</h2>
<p>首先在Xcode中创建一个View-based App，CALayer是属于QuartzCore framework的，所以需要引入QuartzCore framework，另外在程序中包括QuartzCore.h<span style="font-family: monospace; color: #6e371a; font-size: small;"><span style="line-height: 15px; white-space: pre; ">。</span></span></p>
<p>第一个例子是创建一个带圆角的层，在你的ViewController中的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 />4<br />5<br />6<br />7<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;">// Import QuartzCore.h at the top of the file</span><br />
<span style="color: #6e371a;">#import &lt;QuartzCore/QuartzCore.h&gt;</span><br />
<br />
<span style="color: #11740a; font-style: italic;">// Uncomment viewDidLoad and add the following lines</span><br />
self.view.layer.backgroundColor <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span>UIColor orangeColor<span style="color: #002200;">&#93;</span>.CGColor;<br />
self.view.layer.cornerRadius <span style="color: #002200;">=</span><span style="color: #2400d9;">20.0</span>;<br />
self.view.layer.frame <span style="color: #002200;">=</span> CGRectInset<span style="color: #002200;">&#40;</span>self.view.layer.frame, 20, 20<span style="color: #002200;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>结果如下：</p>
<p style="text-align: center; "><a href="http://www.iphone-geek.cn/wp-content/uploads/2011/01/1.jpg"><img class="size-full wp-image-1106 aligncenter" title="Simple Layer" src="http://www.iphone-geek.cn/wp-content/uploads/2011/01/1.jpg" alt="Simple Layer" width="320" height="480" /></a></p>
<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 />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CALayer <span style="color: #002200;">*</span>sublayer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>CALayer layer<span style="color: #002200;">&#93;</span>;<br />
sublayer.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor blueColor<span style="color: #002200;">&#93;</span>.CGColor;<br />
sublayer.shadowOffset <span style="color: #002200;">=</span> CGSizeMake<span style="color: #002200;">&#40;</span>0, 3<span style="color: #002200;">&#41;</span>;<br />
sublayer.shadowRadius <span style="color: #002200;">=</span> <span style="color: #2400d9;">5.0</span>;<br />
sublayer.shadowColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor blackColor<span style="color: #002200;">&#93;</span>.CGColor;<br />
sublayer.shadowOpacity <span style="color: #002200;">=</span> <span style="color: #2400d9;">0.8</span>;<br />
sublayer.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>30, 30, 128, 192<span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#91;</span>self.view.layer addSublayer<span style="color: #002200;">:</span>sublayer<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>效果图：<br />
<a href="http://www.iphone-geek.cn/wp-content/uploads/2011/01/2.jpg"><img class="aligncenter size-full wp-image-1108" title="2" src="http://www.iphone-geek.cn/wp-content/uploads/2011/01/2.jpg" alt="2" width="320" height="480" /></a></p>
<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 />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">sublayer.contents <span style="color: #002200;">=</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;BattleMapSplashScreen.png&quot;</span><span style="color: #002200;">&#93;</span>.CGImage;<br />
sublayer.borderColor <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span>UIColor blackColor<span style="color: #002200;">&#93;</span>.CGColor;<br />
sublayer.borderWidth <span style="color: #002200;">=</span><span style="color: #2400d9;">2.0</span>;</div></td></tr></tbody></table></div>
<p>效果图：<br />
<a href="http://www.iphone-geek.cn/wp-content/uploads/2011/01/3.jpg"><img class="aligncenter size-full wp-image-1110" title="3" src="http://www.iphone-geek.cn/wp-content/uploads/2011/01/3.jpg" alt="3" width="320" height="480" /></a></p>
<p>如果你希望子层也是圆角怎么办？你可能说很容易设置cornerRadius属性就行。实际上你即算是设置了cornerRadius属性，图片仍然不会显示圆角。你还需要设置masksToBounds为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 />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 /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CALayer <span style="color: #002200;">*</span>sublayer <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span>CALayer layer<span style="color: #002200;">&#93;</span>;<br />
sublayer.backgroundColor <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span>UIColor blueColor<span style="color: #002200;">&#93;</span>.CGColor;<br />
sublayer.shadowOffset <span style="color: #002200;">=</span> CGSizeMake<span style="color: #002200;">&#40;</span>0, 3<span style="color: #002200;">&#41;</span>;<br />
sublayer.shadowRadius <span style="color: #002200;">=</span><span style="color: #2400d9;">5.0</span>;<br />
sublayer.shadowColor <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span>UIColor blackColor<span style="color: #002200;">&#93;</span>.CGColor;<br />
sublayer.shadowOpacity <span style="color: #002200;">=</span><span style="color: #2400d9;">0.8</span>;<br />
sublayer.frame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>30, 30, 128, 192<span style="color: #002200;">&#41;</span>;<br />
sublayer.borderColor <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span>UIColor blackColor<span style="color: #002200;">&#93;</span>.CGColor;<br />
sublayer.borderWidth <span style="color: #002200;">=</span><span style="color: #2400d9;">2.0</span>;<br />
sublayer.cornerRadius <span style="color: #002200;">=</span><span style="color: #2400d9;">10.0</span>;<br />
<span style="color: #002200;">&#91;</span>self.view.layer addSublayer<span style="color: #002200;">:</span>sublayer<span style="color: #002200;">&#93;</span>;<br />
<br />
CALayer <span style="color: #002200;">*</span>imageLayer <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span>CALayer layer<span style="color: #002200;">&#93;</span>;<br />
imageLayer.frame <span style="color: #002200;">=</span> sublayer.bounds;<br />
imageLayer.cornerRadius <span style="color: #002200;">=</span><span style="color: #2400d9;">10.0</span>;<br />
imageLayer.contents <span style="color: #002200;">=</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;BattleMapSplashScreen.png&quot;</span><span style="color: #002200;">&#93;</span>.CGImage;<br />
imageLayer.masksToBounds <span style="color: #002200;">=</span><span style="color: #a61390;">YES</span>;<br />
<span style="color: #002200;">&#91;</span>sublayer addSublayer<span style="color: #002200;">:</span>imageLayer<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>效果图：<br />
<a href="http://www.iphone-geek.cn/wp-content/uploads/2011/01/4.jpg"><img class="aligncenter size-full wp-image-1111" title="4" src="http://www.iphone-geek.cn/wp-content/uploads/2011/01/4.jpg" alt="4" width="320" height="480" /></a></p>
<p>最后，还介绍一下自绘图型的实现，其要点是要设置所绘制层的delegate。比如在我们的例子中使用ViewController作为delegate，那么就需要在ViewController中实现drawLayer:inContext方法，对层进行绘制工作。另外，还需要调用setNeedsDisplay，来通知层需要进行绘制了，于是层才会通过对delegate的drawLayer:inContext方法进行调用。</p>
<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 />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 />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<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;">void</span> MyDrawColoredPattern <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">*</span>info, CGContextRef context<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span><br />
&nbsp;<br />
&nbsp; &nbsp; CGColorRef dotColor <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span>UIColor colorWithHue<span style="color: #002200;">:</span>0 saturation<span style="color: #002200;">:</span>0 brightness<span style="color: #002200;">:</span>0.07 alpha<span style="color: #002200;">:</span>1.0<span style="color: #002200;">&#93;</span>.CGColor;<br />
&nbsp; &nbsp; CGColorRef shadowColor <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span>UIColor colorWithRed<span style="color: #002200;">:</span>1 green<span style="color: #002200;">:</span>1 blue<span style="color: #002200;">:</span>1 alpha<span style="color: #002200;">:</span>0.1<span style="color: #002200;">&#93;</span>.CGColor;<br />
&nbsp;<br />
&nbsp; &nbsp; CGContextSetFillColorWithColor<span style="color: #002200;">&#40;</span>context, dotColor<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextSetShadowWithColor<span style="color: #002200;">&#40;</span>context, CGSizeMake<span style="color: #002200;">&#40;</span>0, 1<span style="color: #002200;">&#41;</span>, 1, shadowColor<span style="color: #002200;">&#41;</span>;<br />
&nbsp;<br />
&nbsp; &nbsp; CGContextAddArc<span style="color: #002200;">&#40;</span>context, 3, 3, 4, 0, radians<span style="color: #002200;">&#40;</span>360<span style="color: #002200;">&#41;</span>, 0<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextFillPath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;<br />
&nbsp;<br />
&nbsp; &nbsp; CGContextAddArc<span style="color: #002200;">&#40;</span>context, 16, 16, 4, 0, radians<span style="color: #002200;">&#40;</span>360<span style="color: #002200;">&#41;</span>, 0<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextFillPath<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;<br />
&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;">void</span><span style="color: #002200;">&#41;</span>drawLayer<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CALayer <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>layer inContext<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGContextRef<span style="color: #002200;">&#41;</span>context <span style="color: #002200;">&#123;</span><br />
&nbsp;<br />
&nbsp; &nbsp; CGColorRef bgColor <span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span>UIColor colorWithHue<span style="color: #002200;">:</span>0.6 saturation<span style="color: #002200;">:</span>1.0 brightness<span style="color: #002200;">:</span>1.0 alpha<span style="color: #002200;">:</span>1.0<span style="color: #002200;">&#93;</span>.CGColor;<br />
&nbsp; &nbsp; CGContextSetFillColorWithColor<span style="color: #002200;">&#40;</span>context, bgColor<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextFillRect<span style="color: #002200;">&#40;</span>context, layer.bounds<span style="color: #002200;">&#41;</span>;<br />
&nbsp;<br />
&nbsp; &nbsp; staticconst CGPatternCallbacks callbacks <span style="color: #002200;">=</span><span style="color: #002200;">&#123;</span>0, <span style="color: #002200;">&amp;</span>MyDrawColoredPattern, <span style="color: #a61390;">NULL</span><span style="color: #002200;">&#125;</span>;<br />
&nbsp;<br />
&nbsp; &nbsp; CGContextSaveGState<span style="color: #002200;">&#40;</span>context<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGColorSpaceRef patternSpace <span style="color: #002200;">=</span> CGColorSpaceCreatePattern<span style="color: #002200;">&#40;</span><span style="color: #a61390;">NULL</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextSetFillColorSpace<span style="color: #002200;">&#40;</span>context, patternSpace<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGColorSpaceRelease<span style="color: #002200;">&#40;</span>patternSpace<span style="color: #002200;">&#41;</span>;<br />
&nbsp;<br />
&nbsp; &nbsp; CGPatternRef pattern <span style="color: #002200;">=</span> CGPatternCreate<span style="color: #002200;">&#40;</span><span style="color: #a61390;">NULL</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;layer.bounds,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CGAffineTransformIdentity,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;24,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;24,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;kCGPatternTilingConstantSpacing,<br />
&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: #a61390;">true</span>,<br />
&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;">&amp;</span>callbacks<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGFloat alpha <span style="color: #002200;">=</span><span style="color: #2400d9;">1.0</span>;<br />
&nbsp; &nbsp; CGContextSetFillPattern<span style="color: #002200;">&#40;</span>context, pattern, <span style="color: #002200;">&amp;</span>alpha<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGPatternRelease<span style="color: #002200;">&#40;</span>pattern<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; CGContextFillRect<span style="color: #002200;">&#40;</span>context, layer.bounds<span style="color: #002200;">&#41;</span>;<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>还需要注意，radians是一个自定义函数：</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: #a61390;">static</span> inline <span style="color: #a61390;">double</span> radians <span style="color: #002200;">&#40;</span><span style="color: #a61390;">double</span> degrees<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span> <span style="color: #a61390;">return</span> degrees <span style="color: #002200;">*</span> M_PI<span style="color: #002200;">/</span><span style="color: #2400d9;">180</span>; <span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>效果如下：<br />
<a href="http://www.iphone-geek.cn/wp-content/uploads/2011/01/5.jpg"><img class="aligncenter size-full wp-image-1112" title="5" src="http://www.iphone-geek.cn/wp-content/uploads/2011/01/5.jpg" alt="5" width="320" height="480" /></a></p>
<p>本文的完整代码<a title="下载" href="http://www.raywenderlich.com/downloads/LayerFun.zip">下载</a>。</p>
<h5>原文见：<a title="Introduction to CALayers Tutorial" href="http://www.raywenderlich.com/2502/introduction-to-calayers-tutorial">Introduction to CALayers Tutorial</a></h5>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/calayer%e7%ae%80%e5%8d%95%e6%95%99%e7%a8%8b/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%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>怎样处理EXC_BAD_ACCESS</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%80%8e%e6%a0%b7%e5%a4%84%e7%90%86exc_bad_access</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%80%8e%e6%a0%b7%e5%a4%84%e7%90%86exc_bad_access#comments</comments>
		<pubDate>Fri, 22 Oct 2010 02:54:50 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[调试]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1074</guid>
		<description><![CDATA[相信很多人都知道通过NSZombies来帮助调试出现EXC_BAD_ACCESS的情况,但有时还是找不到需要的信息,那么应该怎么办呢?
下面通过一个例子来说明.下面是hello world的代码:
123NSString* hello = &#91;NSString stringWithFormat:@&#34;Hello world&#34;&#93;;
NSLog&#40;@&#34;What you say is %@&#34;,hello&#41;;
&#91;hello release&#93;;
运行后出现EXC_BAD_ACCESS错误.但没有其他任何提示,这时候通过右击executables下的应用程序名,选择get info后,在arguments下输入环境变量(NSZombieEnabled,MallocStackLogging),如图所示:

再次运行后程序crash,如图:

这次可以看到问题是&#8221;message sent to dealloced object&#8221;了,但具体是哪个语句引起的还并不知道,于是需要在gdb上输入以下语句:

shell malloc_history pid address

那么pid和address是什么呢?再看下crash的图片结合一下我以下使用的命令,你应该很快就可以判定pid和address是从哪里来的了,我的命令是:

shell malloc_history 596 0&#215;5f3ef80

再次运行,程序crash时会出现大量的stack trace信息,如下图是与本程序相关的:

根据这些信息大家就可以找到问题出现在[BadAccessViewController viewDidLoad] 中与 +[NSString stringWithFormat:] 有关的地方.
最后大家记得把环境变量NSZombieEnabled,MallocStackLogging删除或设置为NO,因为它们会使得内存不会被释放.
]]></description>
			<content:encoded><![CDATA[<p>相信很多人都知道通过NSZombies来帮助调试出现EXC_BAD_ACCESS的情况,但有时还是找不到需要的信息,那么应该怎么办呢?</p>
<p>下面通过一个例子来说明.下面是hello world的代码:</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"><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> hello <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;Hello world&quot;</span><span style="color: #002200;">&#93;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;What you say is %@&quot;</span>,hello<span style="color: #002200;">&#41;</span>;<br />
<span style="color: #002200;">&#91;</span>hello release<span style="color: #002200;">&#93;</span>;</div></td></tr></tbody></table></div>
<p>运行后出现EXC_BAD_ACCESS错误.但没有其他任何提示,这时候通过右击executables下的应用程序名,选择get info后,在arguments下输入环境变量(NSZombieEnabled,MallocStackLogging),如图所示:</p>
<p><a href="http://www.iphone-geek.cn/wp-content/uploads/2010/10/add_zombie.png"><img class="alignnone size-full wp-image-1075" title="add_zombie" src="http://www.iphone-geek.cn/wp-content/uploads/2010/10/add_zombie.png" alt="add_zombie" width="592" height="421" /></a></p>
<p>再次运行后程序crash,如图:<br />
<a href="http://www.iphone-geek.cn/wp-content/uploads/2010/10/crash.png"><img class="alignnone size-medium wp-image-1076" title="crash" src="http://www.iphone-geek.cn/wp-content/uploads/2010/10/crash-300x245.png" alt="crash" width="300" height="245" /></a></p>
<p>这次可以看到问题是&#8221;message sent to dealloced object&#8221;了,但具体是哪个语句引起的还并不知道,于是需要在gdb上输入以下语句:</p>
<blockquote><p>
shell malloc_history pid address
</p></blockquote>
<p>那么pid和address是什么呢?再看下crash的图片结合一下我以下使用的命令,你应该很快就可以判定pid和address是从哪里来的了,我的命令是:</p>
<blockquote><p>
shell malloc_history 596 0&#215;5f3ef80
</p></blockquote>
<p>再次运行,程序crash时会出现大量的stack trace信息,如下图是与本程序相关的:<br />
<a href="http://www.iphone-geek.cn/wp-content/uploads/2010/10/malloc_history.png"><img src="http://www.iphone-geek.cn/wp-content/uploads/2010/10/malloc_history-300x22.png" alt="malloc_history" title="malloc_history" width="300" height="22" class="alignnone size-medium wp-image-1077" /></a></p>
<p>根据这些信息大家就可以找到问题出现在[BadAccessViewController viewDidLoad] 中与 +[NSString stringWithFormat:] 有关的地方.</p>
<p>最后大家记得把环境变量NSZombieEnabled,MallocStackLogging删除或设置为NO,因为它们会使得内存不会被释放.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%80%8e%e6%a0%b7%e5%a4%84%e7%90%86exc_bad_access/feed</wfw:commentRss>
		<slash:comments>4</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>
		<item>
		<title>都是Backgrounder惹的祸 &#8211; 解决“越狱”真机调试的问题</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e9%83%bd%e6%98%afbackgrounder%e6%83%b9%e7%9a%84%e7%a5%b8-%e8%a7%a3%e5%86%b3%e2%80%9c%e8%b6%8a%e7%8b%b1%e2%80%9d%e7%9c%9f%e6%9c%ba%e8%b0%83%e8%af%95%e7%9a%84%e9%97%ae%e9%a2%98</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e9%83%bd%e6%98%afbackgrounder%e6%83%b9%e7%9a%84%e7%a5%b8-%e8%a7%a3%e5%86%b3%e2%80%9c%e8%b6%8a%e7%8b%b1%e2%80%9d%e7%9c%9f%e6%9c%ba%e8%b0%83%e8%af%95%e7%9a%84%e9%97%ae%e9%a2%98#comments</comments>
		<pubDate>Sun, 08 Aug 2010 05:07:22 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[调试]]></category>
		<category><![CDATA[Xcode]]></category>
		<category><![CDATA[后台程序]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1038</guid>
		<description><![CDATA[我的iPhone越狱后，在用Xcode进行调试时出现以下错误信息：

warning: Unable to read symbols for &#8220;/Library/MobileSubstrate/DynamicLibraryies/libstatusbar.dylib” (file not found).
Program received singal: &#8220;SIGUSR1&#8243;.

上网查了一下原来是Backgrounder在作怪，最简单的解决方法就是在Backgournder的overrides设定中，禁止要调试的程序以background模式运行即可。

想要知道具体原因，请参见：Backgrounder vs. Build and Run
]]></description>
			<content:encoded><![CDATA[<p>我的iPhone越狱后，在用Xcode进行调试时出现以下错误信息：<br />
<br class="spacer_" /><br />
warning: Unable to read symbols for &#8220;/Library/MobileSubstrate/DynamicLibraryies/libstatusbar.dylib” (file not found).</p>
<p>Program received singal: &#8220;SIGUSR1&#8243;.<br />
<br class="spacer_" /><br />
上网查了一下原来是Backgrounder在作怪，最简单的解决方法就是在Backgournder的overrides设定中，禁止要调试的程序以background模式运行即可。<br />
<br class="spacer_" /><br />
想要知道具体原因，请参见：<a title="Backgrounder vs. Build and Run" href="http://www.alexwhittemore.com/?p=412">Backgrounder vs. Build and Run</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e9%83%bd%e6%98%afbackgrounder%e6%83%b9%e7%9a%84%e7%a5%b8-%e8%a7%a3%e5%86%b3%e2%80%9c%e8%b6%8a%e7%8b%b1%e2%80%9d%e7%9c%9f%e6%9c%ba%e8%b0%83%e8%af%95%e7%9a%84%e9%97%ae%e9%a2%98/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

