<?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/%e6%8f%90%e7%a4%ba%e4%b8%8e%e6%8a%80%e5%b7%a7/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 News Stand应用程序之一 &#8211; 外观</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%88%9b%e5%bb%baios-5-news-stand%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e4%b9%8b%e4%b8%80-%e5%a4%96%e8%a7%82</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%88%9b%e5%bb%baios-5-news-stand%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e4%b9%8b%e4%b8%80-%e5%a4%96%e8%a7%82#comments</comments>
		<pubDate>Fri, 21 Oct 2011 02:52:06 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[用户界面]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[Newsstand]]></category>
		<category><![CDATA[提示与技巧]]></category>
		<category><![CDATA[教程]]></category>

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

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

1. 让程序运行于News Stand内

可以在Info.plist中添加

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

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



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


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

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

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

你可以直接修改Info.plist

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

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

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

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

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

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1180</guid>
		<description><![CDATA[昨晚装上了Lion（10.7），从App Store下载了Xcode 4.1，App Store果然了得，速度非常快，3点多g的东西，只花了我1个小时。兴冲冲地安装后，编译我最新的程序，然后准备放些内容到Simulator下的Documents文件夹下进行测试，问题来了。整个Library目录从用户目录下完全消失了。难道Apple又来了个“乾坤大挪移”？经过研究发现，原来Library目录还在原来的地方，只是被Apple隐藏起来了，这点非常令人不解，其系统下的Library目录都没有隐藏，用户目录下的Library倒被隐藏了。
解决方法非常简单：

chflags nohidden $HOME/Library

再打开Finder，你就可以在你的用户目录下看到Library了。
]]></description>
			<content:encoded><![CDATA[<p>昨晚装上了Lion（10.7），从App Store下载了Xcode 4.1，App Store果然了得，速度非常快，3点多g的东西，只花了我1个小时。兴冲冲地安装后，编译我最新的程序，然后准备放些内容到Simulator下的Documents文件夹下进行测试，问题来了。整个Library目录从用户目录下完全消失了。难道Apple又来了个“乾坤大挪移”？经过研究发现，原来Library目录还在原来的地方，只是被Apple隐藏起来了，这点非常令人不解，其系统下的Library目录都没有隐藏，用户目录下的Library倒被隐藏了。</p>
<p>解决方法非常简单：</p>
<blockquote>
<p>chflags nohidden $HOME/Library</p>
</blockquote>
<p>再打开Finder，你就可以在你的用户目录下看到Library了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e6%8a%80%e5%b7%a7%e4%b8%8e%e6%8f%90%e7%a4%ba/%e5%88%9d%e6%8e%a2%e2%80%9c%e7%8b%ae%e7%a9%b4%e2%80%9d/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>不需重新编译而更改app资源内容的简单方法</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e4%b8%8d%e9%9c%80%e9%87%8d%e6%96%b0%e7%bc%96%e8%af%91%e8%80%8c%e6%9b%b4%e6%94%b9app%e8%b5%84%e6%ba%90%e5%86%85%e5%ae%b9%e7%9a%84%e7%ae%80%e5%8d%95%e6%96%b9%e6%b3%95</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e4%b8%8d%e9%9c%80%e9%87%8d%e6%96%b0%e7%bc%96%e8%af%91%e8%80%8c%e6%9b%b4%e6%94%b9app%e8%b5%84%e6%ba%90%e5%86%85%e5%ae%b9%e7%9a%84%e7%ae%80%e5%8d%95%e6%96%b9%e6%b3%95#comments</comments>
		<pubDate>Tue, 24 May 2011 02:36:22 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[基础]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[提示与技巧]]></category>

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

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

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

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1169</guid>
		<description><![CDATA[我们经常会遇到这种情况，某个按钮太小很难按到，又不想把按钮图片做得太大。我把它作成了一个Class Method，放在了我的Utils类中。
123456789101112131415+&#40;void&#41;resizeTouchableAreaForButton:&#40;UIButton* &#41;button withNewSize:&#40;CGSize&#41;size
&#123;
&#160; &#160; // increase margin around button based on width
&#160; &#160; const CGFloat margin_h = 0.5f * &#40; size.width - button.frame.size.width &#41;;
&#160; &#160; const CGFloat margin_v = 0.5f * &#40; size.height - button.frame.size.height &#41;;
&#160; &#160; 
&#160; &#160; // add margin on all four sides of the button
&#160; &#160; CGRect newFrame = button.frame;
&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>我们经常会遇到这种情况，某个按钮太小很难按到，又不想把按钮图片做得太大。我把它作成了一个Class Method，放在了我的Utils类中。</p>
<div class="codecolorer-container objc mac-classic" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">+</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>resizeTouchableAreaForButton<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIButton<span style="color: #002200;">*</span> <span style="color: #002200;">&#41;</span>button withNewSize<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>CGSize<span style="color: #002200;">&#41;</span>size<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// increase margin around button based on width</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">const</span> CGFloat margin_h <span style="color: #002200;">=</span> 0.5f <span style="color: #002200;">*</span> <span style="color: #002200;">&#40;</span> size.width <span style="color: #002200;">-</span> button.frame.size.width <span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">const</span> CGFloat margin_v <span style="color: #002200;">=</span> 0.5f <span style="color: #002200;">*</span> <span style="color: #002200;">&#40;</span> size.height <span style="color: #002200;">-</span> button.frame.size.height <span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// add margin on all four sides of the button</span><br />
&nbsp; &nbsp; CGRect newFrame <span style="color: #002200;">=</span> button.frame;<br />
&nbsp; &nbsp; newFrame.origin.x <span style="color: #002200;">-=</span> margin_h;<br />
&nbsp; &nbsp; newFrame.origin.y <span style="color: #002200;">-=</span> margin_v;<br />
&nbsp; &nbsp; newFrame.size.width &nbsp;<span style="color: #002200;">+=</span> 2.0f <span style="color: #002200;">*</span> margin_h;<br />
&nbsp; &nbsp; newFrame.size.height <span style="color: #002200;">+=</span> 2.0f <span style="color: #002200;">*</span> margin_v;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; button.frame <span style="color: #002200;">=</span> newFrame;<br />
<span style="color: #002200;">&#125;</span></div></td></tr></tbody></table></div>
<p>这段代码把按钮的可按区域扩大到新的尺寸。不过有一个前提是使用UIButton的setImage而不是setBackgroundImage来设置按钮图片。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e5%88%86%e4%ba%ab%e4%b8%80%e5%b0%8f%e6%ae%b5%e4%bb%a3%e7%a0%81/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>怎样关闭后台运行</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%80%8e%e6%a0%b7%e5%85%b3%e9%97%ad%e5%90%8e%e5%8f%b0%e8%bf%90%e8%a1%8c</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%80%8e%e6%a0%b7%e5%85%b3%e9%97%ad%e5%90%8e%e5%8f%b0%e8%bf%90%e8%a1%8c#comments</comments>
		<pubDate>Fri, 25 Mar 2011 00:15:47 +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=1148</guid>
		<description><![CDATA[iOS 4引进了所谓多任务，可以让程序运行于后台，不过对目前大部分程序而言这只是一个鸡肋。有没有办法直接在用户按下Home键后像iOS 4之前的程序一样直接退出呢？方法如下：

打开info.plist
加入 UIApplicationExitsOnSuspend 或者选择“Application does not run in background（程序不运行于后台）”
将其设为 YES

]]></description>
			<content:encoded><![CDATA[<p>iOS 4引进了所谓多任务，可以让程序运行于后台，不过对目前大部分程序而言这只是一个鸡肋。有没有办法直接在用户按下Home键后像iOS 4之前的程序一样直接退出呢？方法如下：</p>
<ol>
<li>打开info.plist</li>
<li>加入 <strong>UIApplicationExitsOnSuspend</strong> 或者选择“Application does not run in background（程序不运行于后台）”</li>
<li>将其设为 YES</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/%e6%80%8e%e6%a0%b7%e5%85%b3%e9%97%ad%e5%90%8e%e5%8f%b0%e8%bf%90%e8%a1%8c/feed</wfw:commentRss>
		<slash:comments>0</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>怎样从ipa中提取PNG文件</title>
		<link>http://www.iphone-geek.cn/%e6%8a%80%e5%b7%a7%e4%b8%8e%e6%8f%90%e7%a4%ba/%e6%80%8e%e6%a0%b7%e4%bb%8eipa%e4%b8%ad%e6%8f%90%e5%8f%96png%e6%96%87%e4%bb%b6</link>
		<comments>http://www.iphone-geek.cn/%e6%8a%80%e5%b7%a7%e4%b8%8e%e6%8f%90%e7%a4%ba/%e6%80%8e%e6%a0%b7%e4%bb%8eipa%e4%b8%ad%e6%8f%90%e5%8f%96png%e6%96%87%e4%bb%b6#comments</comments>
		<pubDate>Mon, 03 Jan 2011 16:52:41 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[技巧与提示]]></category>
		<category><![CDATA[提示与技巧]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1096</guid>
		<description><![CDATA[众所周知，ipa实际上就是一个zip文件，通过解压，可以在Payload目录下得到一个app文件，实际上这个app文件就是一个文件夹，当然windows下，用户很容易就知道这一点。在Mac下，用户需要将app更名。进入此目录后，ipa中的所有resource文件都尽收眼底了。不过，所有的png文件都无法读取。这是由于Apple在将png打包加入ipa之前将png以一种特殊格式存放，要读取此格式就要破译Apple所采用的png格式了。
不过幸运的是，有人已经做了这部分工作，见iPhone PNG Images Normalizer Python，这里是采用python对png进行转换，大家如果有兴趣，可以仔细读一下源代码，如果只是想获取可读的png文件，请在上述网站进行下载或在本地下载ipin.py.zip。
此python程序的使用方法很简单，当然首先系统中要求安装了python。解压ipin.py.zip后，将ipin.py文件复制到刚才解压的包括所有png文件的目录下，然后运行：

python ipin.py

回答Y，所有的png将被转换成通常的png格式，这样你使用预览程序就可以看到了。
]]></description>
			<content:encoded><![CDATA[<p>众所周知，ipa实际上就是一个zip文件，通过解压，可以在Payload目录下得到一个app文件，实际上这个app文件就是一个文件夹，当然windows下，用户很容易就知道这一点。在Mac下，用户需要将app更名。进入此目录后，ipa中的所有resource文件都尽收眼底了。不过，所有的png文件都无法读取。这是由于Apple在将png打包加入ipa之前将png以一种特殊格式存放，要读取此格式就要破译Apple所采用的png格式了。</p>
<p>不过幸运的是，有人已经做了这部分工作，见<a href="http://www.axelbrz.com.ar/?mod=iphone-png-images-normalizer">iPhone PNG Images Normalizer Python</a>，这里是采用python对png进行转换，大家如果有兴趣，可以仔细读一下源代码，如果只是想获取可读的png文件，请在上述网站进行下载或在本地下载<a href='http://www.iphone-geek.cn/wp-content/uploads/2011/01/ipin.py.zip'>ipin.py.zip</a>。</p>
<p>此python程序的使用方法很简单，当然首先系统中要求安装了python。解压ipin.py.zip后，将ipin.py文件复制到刚才解压的包括所有png文件的目录下，然后运行：</p>
<blockquote><p>
python ipin.py
</p></blockquote>
<p>回答Y，所有的png将被转换成通常的png格式，这样你使用预览程序就可以看到了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e6%8a%80%e5%b7%a7%e4%b8%8e%e6%8f%90%e7%a4%ba/%e6%80%8e%e6%a0%b7%e4%bb%8eipa%e4%b8%ad%e6%8f%90%e5%8f%96png%e6%96%87%e4%bb%b6/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>IAP transaction error</title>
		<link>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/iap-transaction-error</link>
		<comments>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/iap-transaction-error#comments</comments>
		<pubDate>Thu, 04 Nov 2010 04:05:36 +0000</pubDate>
		<dc:creator>bagusflyer</dc:creator>
				<category><![CDATA[IAP]]></category>
		<category><![CDATA[编程]]></category>
		<category><![CDATA[调试]]></category>
		<category><![CDATA[提示与技巧]]></category>

		<guid isPermaLink="false">http://www.iphone-geek.cn/?p=1089</guid>
		<description><![CDATA[这几天测试IAP时，总是出现下列错误：

You&#8217;ve already purchased this but it hasn&#8217;t been downloaded&#8230;..

然后就是，Transaction Failed，错误原因是：无法连接iTune Store。上网查了一下很多人说是iTunes Store的问题，等几天就好了，但我用另一个iDP的账户又没有问题。进过调试，最后发现问题出在iTune Store 的 test account上，原来我没有为新iDP账户创建test account，这原来是个低级错误，不过Apple的错误信息也太容易误导人了吧？
]]></description>
			<content:encoded><![CDATA[<p>这几天测试IAP时，总是出现下列错误：</p>
<blockquote><p>
You&#8217;ve already purchased this but it hasn&#8217;t been downloaded&#8230;..
</p></blockquote>
<p>然后就是，Transaction Failed，错误原因是：无法连接iTune Store。上网查了一下很多人说是iTunes Store的问题，等几天就好了，但我用另一个iDP的账户又没有问题。进过调试，最后发现问题出在iTune Store 的 test account上，原来我没有为新iDP账户创建test account，这原来是个低级错误，不过Apple的错误信息也太容易误导人了吧？</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iphone-geek.cn/%e7%bc%96%e7%a8%8b/iap-transaction-error/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

