<?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>Floyd's Thoughts... &#187; UIKit</title>
	<atom:link href="http://www.floydprice.com/category/uikit/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.floydprice.com</link>
	<description>Because Everything is Interesting!!!</description>
	<lastBuildDate>Fri, 18 Jun 2010 05:32:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to respond to the IPhone Shake Gesture</title>
		<link>http://www.floydprice.com/2009/10/how-to-respond-to-the-iphone-shake-gesture/</link>
		<comments>http://www.floydprice.com/2009/10/how-to-respond-to-the-iphone-shake-gesture/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 19:48:02 +0000</pubDate>
		<dc:creator>Floyd Price</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[IPhone]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[UIKit]]></category>

		<guid isPermaLink="false">http://www.floydprice.com/?p=148</guid>
		<description><![CDATA[The IPhone 3.0 SDK includes support for detecting when a user &#8220;Shakes&#8221; the IPhone, this is intended to be a usability feature allowing app developers to implement Refresh or Read All functions on shake, wow those crazy guys at Apple really do know how to innovate! It&#8217;s pretty easy to implement all you need to [...]]]></description>
			<content:encoded><![CDATA[<p>The IPhone 3.0 SDK includes support for detecting when a user &#8220;Shakes&#8221; the IPhone, this is intended to be a usability feature allowing app developers to implement Refresh or Read All functions on shake, wow those crazy guys at Apple really do know how to innovate!</p>
<p>It&#8217;s pretty easy to implement all you need to do is register your view controller as the first responder and listen for the motion event.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> viewDidAppear<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>BOOL<span style="color: #009900;">&#41;</span>animated<span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#91;</span>super viewDidAppear<span style="color: #339933;">:</span>animated<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#91;</span>self becomeFirstResponder<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Once your controller is the First Responder you can receive the motion event like so:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>motionEnded<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>UIEventSubtype<span style="color: #009900;">&#41;</span>motion withEvent<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span>UIEvent <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>event
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>motion <span style="color: #339933;">==</span> UIEventSubtypeMotionShake<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		refresh<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This will work beautifully but you will however notice that any views you present over this one will not respond to all touch events, for instance the keyboard will not show when you touch a text field, this is because you need to resign the First Responder before you present the view like so:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>IBAction<span style="color: #009900;">&#41;</span>showMyCustomView <span style="color: #009900;">&#123;</span>    
	<span style="color: #009900;">&#91;</span>self resignFirstResponder<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#91;</span>self presentModalViewController<span style="color: #339933;">:</span>myCustomViewController animated<span style="color: #339933;">:</span>YES<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see this is all pretty easy and the only gotcha is the First Responder stuff, which also is pretty trivial.</p>
<p>Enjoy and please people, Shake Responsibly!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.floydprice.com/2009/10/how-to-respond-to-the-iphone-shake-gesture/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
