<?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>ObjColumnist &#187; iPhone</title>
	<atom:link href="http://objcolumnist.com/category/iphone/feed/" rel="self" type="application/rss+xml" />
	<link>http://objcolumnist.com</link>
	<description>Coding under the Hammer</description>
	<lastBuildDate>Tue, 10 Jan 2012 20:27:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Detecting Multitouch Gestures in iOS</title>
		<link>http://objcolumnist.com/2010/11/08/detecting-multitouch-gestures-in-ios/</link>
		<comments>http://objcolumnist.com/2010/11/08/detecting-multitouch-gestures-in-ios/#comments</comments>
		<pubDate>Mon, 08 Nov 2010 19:33:17 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[CocoaTouch]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=284</guid>
		<description><![CDATA[Before iOS 3.2 was introduced on the iPad (and latter with iOS 4.0 on the iPhone and iPod Touch), interpreting touch events as different gestures was an awkward task, and relied upon subclassing UIView, and then implementing the following methods. - &#40;void&#41;touchesBegan:&#40;NSSet *&#41;touches withEvent:&#40;UIEvent *&#41;event; - &#40;void&#41;touchesMoved:&#40;NSSet *&#41;touches withEvent:&#40;UIEvent *&#41;event; - &#40;void&#41;touchesEnded:&#40;NSSet *&#41;touches withEvent:&#40;UIEvent *&#41;event; [...]]]></description>
			<content:encoded><![CDATA[<p>Before iOS 3.2 was introduced on the iPad (and latter with iOS 4.0 on the iPhone and iPod Touch), interpreting touch events as different gestures was an awkward task, and relied upon subclassing UIView, and then implementing the following methods.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>touchesBegan<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSSet</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>touches withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>touchesMoved<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSSet</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>touches withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>touchesEnded<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSSet</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>touches withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>touchesCancelled<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSSet</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>touches withEvent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIEvent <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>event;</pre></div></div>

<p>If you were trying to detect if a user was dragging a view (or panning as Apple would say), you would usually implement the <strong>touchesBegan:withEvent:</strong> to start dragging the piece, <strong>touchesMoved:withEvent:</strong> to adjust the view&#8217;s frame, and then <strong>touchesEnded:withEvent:</strong> and <strong>touchesCancelled:withEvent:</strong> to stop detecting the drag. While implementing dragging was not too complex, trying to detect a more advance gesture such as a swipe or pinch was a lot more complex &#8230; and a lot of hard work to make it replicates Apple&#8217;s version of the gestures accurately. </p>
<p>Thankfully Apple created <strong>UIGestureRecognizer</strong>:</p>
<blockquote><p>
UIGestureRecognizer is an abstract base class for concrete gesture-recognizer classes. A gesture-recognizer object (or, simply, a gesture recognizer) decouples the logic for recognizing a gesture and acting on that recognition. When one of these objects recognizes a common gesture or, in some cases, a change in the gesture, it sends an action message to each designated target object.</p>
<p>Taken from <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html<br />
">Apple</a>
</p></blockquote>
<p>As <strong>UIGestureRecognizer</strong> is an abstract class, you will never use it directly. You will however use one of its subclasses, that have been designed specifically to capture a specific gesture.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UITapGestureRecognizer
UIPinchGestureRecognizer
UIRotationGestureRecognizer
UISwipeGestureRecognizer
UIPanGestureRecognizer
UILongPressGestureRecognizer</pre></div></div>

<p>So lets take <strong>UIPanGestureRecognizer</strong> for an example, and we will use it to move a view around.</p>
<p>Our example view controller has a view (obviously), and this has a subview called <strong>panView</strong>, which is the view we will move around.</p>
<p>First thing that you will need to do, is create a pan gesture recognizer (<strong>UIPanGestureRecognizer</strong>) and add it to the <strong>panView</strong>. This will allow you to detect the gesture. To get informed about the gesture getting detected, you have to set the view controller as the delegate, and then have it call the the<strong> panViewWithGestureRecognizer:</strong> selector. (Note: You can set any object as the delegate, as long as it implements <strong>UIGestureRecognizerDelegate</strong> protocol. For this example the view controller makes sence.)</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIPanGestureRecognizer <span style="color: #002200;">*</span>panGesture <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
panGesture <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIPanGestureRecognizer 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>panViewWithGestureRecognizer<span style="color: #002200;">:</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>panGesture setMaximumNumberOfTouches<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>panGesture setDelegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>panView addGestureRecognizer<span style="color: #002200;">:</span>panGesture<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>panGesture release<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p><strong>panViewWithGestureRecognizer:</strong> will get called when the gesture changes state, the possible states are:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
UIGestureRecognizerStatePossible  
UIGestureRecognizerStateBegan    
UIGestureRecognizerStateChanged   
UIGestureRecognizerStateEnded    
UIGestureRecognizerStatePossible
UIGestureRecognizerStateCancelled   
UIGestureRecognizerStateFailed
UIGestureRecognizerStateRecognized
UIGestureRecognizerStateEnded</pre></div></div>

<p>For this example we only care about if gesture began (<strong>UIGestureRecognizerStateBegan</strong>) or has changed (<strong>UIGestureRecognizerStateChanged</strong>). When a pan gesture happens (begins or changes) we want to move the center of <strong>panView</strong> to be underneath the users finger, thus dragging the piece. </p>
<p>To do this we implement<strong panViewWithGestureRecognizer:</strong> in the following way.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>panViewWithGestureRecognizer<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIPanGestureRecognizer <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>gestureRecognizer
<span style="color: #002200;">&#123;</span>    
&nbsp;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>gestureRecognizer state<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> UIGestureRecognizerStateBegan 
         || <span style="color: #002200;">&#91;</span>gestureRecognizer state<span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> UIGestureRecognizerStateChanged<span style="color: #002200;">&#41;</span> 
    <span style="color: #002200;">&#123;</span>
&nbsp;
        CGPoint translation <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>gestureRecognizer translationInView<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>panView superview<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
        <span style="color: #002200;">&#91;</span>piece setCenter<span style="color: #002200;">:</span>CGPointMake<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>panView center<span style="color: #002200;">&#93;</span>.x <span style="color: #002200;">+</span> translation.x, <span style="color: #002200;">&#91;</span>panView center<span style="color: #002200;">&#93;</span>.y <span style="color: #002200;">+</span> translation.y<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
        <span style="color: #002200;">&#91;</span>gestureRecognizer setTranslation<span style="color: #002200;">:</span>CGPointZero inView<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>panView superview<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>What makes this super easy is the convenience method<strong>translationInView:</strong>, which is found on <strong>UIPanGestureRecognizer</strong>. This gives you the value of where the center of the <strong>panView</strong> should be, without having to calculate it yourself. We then need to set the translation back to zero using <strong>setTranslation:</strong>, so when we calculate the next gesture, it will be from the new position of the <strong>panView</strong>. And thats all there is to it.</p>
<p>As mentioned before there are a few gesture recogniser that have already been prebuilt for you to use, and you can even add multiple gesture recogniser to the same view. If you do this, you will want to implement:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><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;</pre></div></div>

<p>This simply allows you to specify if a gesture should be detected alongside another gesture e.g. a pinch and a rotation gesture. If Apple&#8217;s pre-built gesture recognizers are not enough for you, you can always create your own subclass of <strong>UIGestureRecognizer</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2010/11/08/detecting-multitouch-gestures-in-ios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Core Animation using blocks</title>
		<link>http://objcolumnist.com/2010/09/19/core-animation-using-blocks/</link>
		<comments>http://objcolumnist.com/2010/09/19/core-animation-using-blocks/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 11:27:46 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[CocoaTouch]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=244</guid>
		<description><![CDATA[Previously I have written a blog post about doing simple animations with UIViews, which you can find here. Starting in iOS 4.0 you can now do this with blocks. Blocks have two major benefits (although there are more): They can be used in conjunction with Grand Central Dispatch (GCD), as an alternative to threading. They [...]]]></description>
			<content:encoded><![CDATA[<p>Previously I have written a blog post about doing simple animations with <strong>UIView</strong>s, which you can find <a href="http://objcolumnist.com/2009/07/18/simple-uiview-based-animations-on-the-iphone/">here</a>. Starting in <strong>iOS 4.0</strong> you can now do this with blocks. </p>
<p>Blocks have two major benefits (although there are more):</p>
<ul>
<li>
They can be used in conjunction with<strong> Grand Central Dispatch (GCD)</strong>, as an alternative to threading.
</li>
<li>
They can be used for callbacks, instead of <strong>NSNotification</strong>s, callback selectors, function pointers etc. This is usually done by providing a callback/completion block, and this is what we will be looking at here.
</li>
</ul>
<p>The most common method that you will use to animate views using blocks, is the following class method on <strong>UIView</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>animateWithDuration<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSTimeInterval<span style="color: #002200;">&#41;</span>duration animations<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">^</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>animations completion<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">^</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span> finished<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>completion;</pre></div></div>

<p>This method allows you to set a time interval, along with an animations block and a completion block.</p>
<p>Lets say we have a <strong>UIView</strong> variable called <em>redView</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">redView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">320</span>,<span style="color: #2400d9;">320</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
redView.backgroundColor <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIColor redColor<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>We will then add <em>redView</em> as a subview of the view controller&#8217;s view</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">&#91;</span>self.view addSubview<span style="color: #002200;">:</span>redView<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>A common situation you may find your self in, is when you finish animating a view (e.g. changing its alpha), you would then want to remove it from it&#8217;s superview, and then release it from memory.</p>
<p>So if you had (for example) a method called <em>animate</em> to trigger off the animation, you would need to add an &#8220;animation did stop selector&#8221; to the animation. In the following example I have called it <em>cleanUp</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>animate<span style="color: #002200;">&#123;</span>
&nbsp;
   <span style="color: #002200;">&#91;</span>UIView beginAnimations<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span> context<span style="color: #002200;">:</span><span style="color: #a61390;">NULL</span><span style="color: #002200;">&#93;</span>;
   <span style="color: #002200;">&#91;</span>UIView setAnimationDuration<span style="color: #002200;">:</span><span style="color: #2400d9;">5.0</span><span style="color: #002200;">&#93;</span>;
   <span style="color: #002200;">&#91;</span>UIView setAnimationDidStopSelector<span style="color: #002200;">:</span><span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span>cleanUp<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
   <span style="color: #002200;">&#91;</span>redView setAlpha<span style="color: #002200;">:</span><span style="color: #2400d9;">0.0</span><span style="color: #002200;">&#93;</span>;
   <span style="color: #002200;">&#91;</span>UIView commitAnimations<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>cleanUp<span style="color: #002200;">&#123;</span>
&nbsp;
    <span style="color: #002200;">&#91;</span>redView removeFromSuperview<span style="color: #002200;">&#93;</span>;
    <span style="color: #11740a; font-style: italic;">//I do release and = nil on the same line as a coding convention</span>
    <span style="color: #11740a; font-style: italic;">//so I don't forget to &quot;nil&quot; the variable</span>
    <span style="color: #002200;">&#91;</span>redView release<span style="color: #002200;">&#93;</span>, redView <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;	
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>Although this works well enough, it does mean that your code is split up into the animation code and the (completion) clean up code. If you end up doing this a lot, your code can end up becoming very fragmented and hard to follow.</p>
<p>Using blocks we can do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>animate<span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #002200;">&#91;</span>UIView animateWithDuration<span style="color: #002200;">:</span><span style="color: #2400d9;">5.0</span>
&nbsp;
                            animations<span style="color: #002200;">:^</span><span style="color: #002200;">&#123;</span> 
	                          redView.alpha <span style="color: #002200;">=</span> <span style="color: #2400d9;">0.0</span>; 
	                     <span style="color: #002200;">&#125;</span>
&nbsp;
                           completion<span style="color: #002200;">:^</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span>  completed<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
	                          <span style="color: #002200;">&#91;</span>redView removeFromSuperview<span style="color: #002200;">&#93;</span>;
                                  <span style="color: #002200;">&#91;</span>redView release<span style="color: #002200;">&#93;</span>,redView <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
	                    <span style="color: #002200;">&#125;</span>
 <span style="color: #002200;">&#93;</span>;
&nbsp;
&nbsp;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>This keeps things nice and simple, and it means that you can easily see what code will be executed when the animation completes. </p>
<p>All of the animations you wish to do are passed in using a block:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #002200;">^</span><span style="color: #002200;">&#123;</span> 
redView.alpha <span style="color: #002200;">=</span> <span style="color: #2400d9;">0.0</span>; 
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>This block takes no arguments, and it also does not have a return type (so it defaults to void).</p>
<p>Instead of calling the <em>cleanUp</em> selector, we can simply pass in a completion block:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #002200;">^</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span>  completed<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#123;</span>
<span style="color: #002200;">&#91;</span>redView removeFromSuperview<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>redView release<span style="color: #002200;">&#93;</span>,redView <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>This block takes one parameter, which is a bool signifying if the animation has completed when the block is executed. In this example we ignore the completed variable, and we assume that the animation has completed for simplicity reasons. In the body of the block we do same as we did in the <em>cleanUp</em> selector, we remove <em>redView</em> from its super view and then release it from memory.</p>
<p>In some situations you won&#8217;t need to use blocks for Core Animation, but when you do, you will find it cleans up your code no end.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2010/09/19/core-animation-using-blocks/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Rounding the corners of an UIView</title>
		<link>http://objcolumnist.com/2010/08/15/rounding-the-corners-of-an-uiview/</link>
		<comments>http://objcolumnist.com/2010/08/15/rounding-the-corners-of-an-uiview/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 15:20:12 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[CocoaTouch]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Quick Tip]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=228</guid>
		<description><![CDATA[Rounded corners are all the rage at the moment, so you would think that there would be an API on UIView to do such a thing. If you looked at all of the UIView documentation, you would come to the conclusion that there is not an API to do such a thing, and you would [...]]]></description>
			<content:encoded><![CDATA[<p>Rounded corners are all the rage at the moment, so you would think that there would be an API on <strong>UIView</strong> to do such a thing. If you looked at all of the <strong>UIView</strong> documentation, you would come to the conclusion that there is not an API to do such a thing, and you would be (kind of) wrong.</p>
<p>Although <strong>UIView</strong> does not allow you round its corners, <strong>CALayer</strong> does, and every <strong>UIView</strong> is backed by a <strong>CALayer</strong>.</p>
<p>To access all of the functionality of <strong>CALayer</strong>, you will need to import QuartzCore into any of header/implementation files that you intend to use <strong>CALayer</strong> in.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;QuartzCore/QuartzCore.h&gt;</span></pre></div></div>

<p><strong>CALayer</strong> has a lot of APIs available to it, but the property we are interested in is:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@property</span> CGFloat cornerRadius</pre></div></div>

<p>As the property suggests, this allows you to set the <strong>CALayer</strong>&#8216;s corner radius in points:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIView <span style="color: #002200;">*</span>view <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>frame<span style="color: #002200;">&#93;</span>;
view.layer.cornerRadius <span style="color: #002200;">=</span> <span style="color: #2400d9;">10.0</span>;</pre></div></div>

<p><strong>CALayer</strong> also has properties allowing you to set its border, shadow etc, so all of these can save you a lot of code &#8230; and unwanted images.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2010/08/15/rounding-the-corners-of-an-uiview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Retrieving the currently being played music track</title>
		<link>http://objcolumnist.com/2010/07/11/retrieving-the-currently-being-played-music-track/</link>
		<comments>http://objcolumnist.com/2010/07/11/retrieving-the-currently-being-played-music-track/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 11:48:18 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[CocoaTouch]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=213</guid>
		<description><![CDATA[One question I keep hearing is &#8220;Can you find out what music track a user is listening to? as I want to use it for &#8230;&#8221;, where the reason usually revolves around posting it to a social network network site, or using it as IM status. Thankfully retrieving the currently being played music track is [...]]]></description>
			<content:encoded><![CDATA[<p>One question I keep hearing is &#8220;Can you find out what music track a user is listening to? as I want to use it for &#8230;&#8221;, where the reason usually revolves around posting it to a social network network site, or using it as IM status. Thankfully retrieving the currently being played music track is very easy thanks to the <strong>MediaPlayer Framework</strong>.</p>
<p>Each application has its own <strong>MPMusicPlayerController</strong>, but it also has access to the iPod&#8217;s <strong>MPMusicPlayerController</strong>, using the class method <strong>iPodMusicPlayer</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">MPMusicPlayerController <span style="color: #002200;">*</span>iPodMusicPlayerController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MPMusicPlayerController iPodMusicPlayer<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>After you have got the iPod music player, you can then get the <strong>now playing item</strong></p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">MPMediaItem <span style="color: #002200;">*</span>nowPlayingItem <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>iPodMusicPlayerController nowPlayingItem<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>If the now playing item is <strong>nil</strong>, you know that the user is not playing a music track on their iPod.</p>
<p>Unlike many of the other APIs in iOS, you can&#8217;t access information such as the track name, via a simple string property. You have to use one of the following keys:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyPersistentID;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyMediaType; 
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyTitle;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyAlbumTitle; 
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyArtist; 
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyAlbumArtist; 
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyGenre;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyComposer; 
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyPlaybackDuration;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyAlbumTrackNumber;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyAlbumTrackCount;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyDiscNumber;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyDiscCount;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyArtwork;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyLyrics;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyIsCompilation;  
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyReleaseDate;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyBeatsPerMinute;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyComments;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #a61390;">const</span> MPMediaItemPropertyAssetURL;</pre></div></div>

<p>And then query the Media Player Item, using the instance method <strong>valueForProperty:</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>itemTitle <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>nowPlayingItem valueForProperty<span style="color: #002200;">:</span>MPMediaItemPropertyTitle<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>And thus you will end up with a code snippet like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">MPMusicPlayerController <span style="color: #002200;">*</span>iPodMusicPlayerController <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>MPMusicPlayerController iPodMusicPlayer<span style="color: #002200;">&#93;</span>;
&nbsp;
MPMediaItem <span style="color: #002200;">*</span>nowPlayingItem <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>iPodMusicPlayerController nowPlayingItem<span style="color: #002200;">&#93;</span>;	
&nbsp;
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>nowPlayingItem<span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>itemTitle <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>nowPlayingItem valueForProperty<span style="color: #002200;">:</span>MPMediaItemPropertyTitle<span style="color: #002200;">&#93;</span>;
    NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;User is playing the following song: %@&quot;</span>,itemTitle<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span><span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span>
    NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;User is not playing a song&quot;</span><span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>As always this is just a small code snippet to get you started. There are situations for instance, where the user can have a <strong>now playing item</strong> that has no title (strange I know). So as always you will have to handle these edge cases appropriately.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2010/07/11/retrieving-the-currently-being-played-music-track/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>MapKit</title>
		<link>http://objcolumnist.com/2010/05/16/mapkit/</link>
		<comments>http://objcolumnist.com/2010/05/16/mapkit/#comments</comments>
		<pubDate>Sun, 16 May 2010 19:01:31 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[CocoaTouch]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=199</guid>
		<description><![CDATA[Location, Location, Location is all the rage at the moment. Where did someone last update their social network status ? Where is the nearest restaurant ? Where do I need to be in 5 mins ? the possibilities for location services are (nearly) endless. But what is a location ? well put simple it is [...]]]></description>
			<content:encoded><![CDATA[<p>Location, Location, Location is all the rage at the moment. Where did someone last update their social network status ? Where is the nearest restaurant ? Where do I need to be in 5 mins ? the possibilities for location services are (nearly) endless. But what is a location ? well put simple it is just a co-ordinate value (longitude and latitude), and in the case of iPhone, it is in reference to the earth. But lets be honest, displaying -122.03, 37.33 in your sexy new iPhone application is not very exciting now is it ? That is were <strong>MKMapView</strong> comes in.</p>
<p><strong>MKMapView</strong> allows you to display a Map on your iPhone&#8217;s screen. <strong>MKMapView</strong> is just a subclass of <strong>UIView</strong> so you can treat it like one. You can ether use it as a subview (such as on a profile page), or make it go full screen (using it with its own view controller) such as when you are viewing a map to get directions.</p>
<p>So like <strong>UIView</strong>, to create a <strong>MKMapView</strong> you need to initialise one with a frame:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">MKMapView <span style="color: #002200;">*</span>mapView <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MKMapView alloc<span style="color: #002200;">&#93;</span> initWithFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">320</span>,<span style="color: #2400d9;">480</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Unlike <strong>UIView</strong>, you will also want to become the delegate of <strong>MKMapView</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">mapView.delegate <span style="color: #002200;">=</span> self;</pre></div></div>

<p>The delegate methods for <strong>MKMapView</strong> include ones that inform you about when the map starts and finishes to load, in addition to if it fails to load at all. (These delegate methods are very similar to <strong>UIWebView</strong> if you have used that).</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mapViewWillStartLoadingMap<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKMapView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mapView;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mapViewDidFinishLoadingMap<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKMapView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mapView;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mapViewDidFailLoadingMap<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKMapView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mapView withError<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>error;</pre></div></div>

<p>In addition to the loading of the Map, the delegate also provides call backs for when the map&#8217;s region changes, it also provides callbacks regarding annotation information (more on that later).</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mapView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKMapView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mapView regionWillChangeAnimated<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated;
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mapView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKMapView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mapView regionDidChangeAnimated<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated;</pre></div></div>

<p>After you have created a <strong>MKMapView</strong>, you will want to show a specific region on the map. The method to do this is:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setRegion<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKCoordinateRegion<span style="color: #002200;">&#41;</span>region animated<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>animated;</pre></div></div>

<p>This introduces a new MapKit data type <strong>MKCoordinateRegion</strong>. This is the centre point (that you want to show) expressed as a co-ordinate, and then the distance (span) around this co-ordinate that you want to be shown. In essence the span is the zoom level. The bigger the span, the bigger the area that is displayed on the map.</p>
<p>To make a new region you will need to use:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">MKCoordinateRegionMake<span style="color: #002200;">&#40;</span>CLLocationCoordinate2D centerCoordinate, MKCoordinateSpan span<span style="color: #002200;">&#41;</span>;</pre></div></div>

<p>And thus you will probably have some code that looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">CLLocationCoordinate2D coordinate;
coordinate.latitude <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">122.03</span>;
coordinate.longitude <span style="color: #002200;">=</span> <span style="color: #2400d9;">37.33</span>;
&nbsp;
MKCoordinateSpan  span <span style="color: #002200;">=</span> MKCoordinateSpanMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.003</span>, <span style="color: #2400d9;">0.003</span><span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>mapView setRegion<span style="color: #002200;">:</span>MKCoordinateRegionMake<span style="color: #002200;">&#40;</span>coordinate, MKCoordinateSpanMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">0.003</span>, <span style="color: #2400d9;">0.003</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>After you have focused in on a specific region of the map, you will more than likely want to annotate a given point. To do this you need to create an object that conforms to the (informal) <strong>MKAnnotation</strong> protocol, and in particular implements the <strong>CLLocationCoordinate2D</strong> coordinate property.</p>
<p>e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">@interface</span> MCSMMapAnnotation <span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic<span style="color: #002200;">&#41;</span> CLLocationCoordinate2D coordinate;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<p>Then you just need to create an instance of this model object, and then add it to the map as an annotation:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">MCSMMapAnnotation <span style="color: #002200;">*</span>annotation <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MCSMMapAnnotation alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
CLLocationCoordinate2D annotationCoordinate;
coordinate.latitude <span style="color: #002200;">=</span> <span style="color: #002200;">-</span><span style="color: #2400d9;">122.03</span>;
coordinate.longitude <span style="color: #002200;">=</span> <span style="color: #2400d9;">37.33</span>;
annotation.coordinate <span style="color: #002200;">=</span> annotationCoordinate;
<span style="color: #002200;">&#91;</span>self.mapView addAnnotation<span style="color: #002200;">:</span>annotation<span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>And that is it, nice and simple.</p>
<p>One more thing …</p>
<p>Before I mentioned that there are delegate methods regarding the annotations on the Map View. One that is particular useful is:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mapView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKMapView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mapView didAddAnnotationViews<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>annotationViews;</pre></div></div>

<p>Why is it useful ? Well if you didn&#8217;t notice, doing the above means that the annotation(s) just appear on the screen and they do not drop on. So in this delegate method, you can move the annotations off screen and then put them back to where MapKit said they should be.</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>mapView<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>MKMapView <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>mapView didAddAnnotationViews<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>annotationViews<span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//The final (correct) position of the annotation</span>
CGRect finalFrame;
&nbsp;
<span style="color: #11740a; font-style: italic;">//The position we will drop the annotation from</span>
CGRect offScreenFrame;		
&nbsp;
&nbsp;
<span style="color: #a61390;">for</span><span style="color: #002200;">&#40;</span>UIView <span style="color: #002200;">*</span>annotationView <span style="color: #a61390;">in</span> annotationViews<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//MapKit has worked out the annotations final position so store it</span>
finalFrame <span style="color: #002200;">=</span> annotationView.frame;
&nbsp;
<span style="color: #11740a; font-style: italic;">//We just want to move the annotation, so it is just above the top of the visible screen</span>
&nbsp;
offScreenFrame <span style="color: #002200;">=</span> CGRectMake<span style="color: #002200;">&#40;</span>finalFrame.origin.x,<span style="color: #002200;">&#40;</span>finalFrame.size.height <span style="color: #002200;">*-</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> , finalFrame.size.width, finalFrame.size.height<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">//Set and therefore move the annotation to the off screen position</span>
annotationView.frame <span style="color: #002200;">=</span> offScreenFrame;
&nbsp;
<span style="color: #11740a; font-style: italic;">//Set up an animation block to animate the drop</span>
<span style="color: #002200;">&#91;</span>UIView beginAnimations<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;AnimateAnnotation&quot;</span> context<span style="color: #002200;">:</span><span style="color: #a61390;">NULL</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>UIView setAnimationDuration<span style="color: #002200;">:</span><span style="color: #2400d9;">1.0</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">//Set the final frame, to be the frame that map kit originally calculated</span>
annotationView.frame <span style="color: #002200;">=</span> finalFrame;
<span style="color: #002200;">&#91;</span>UIView commitAnimations<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>This is just a brief overview of what you can do with MapKit. The most obvious thing you can do, is to add more than one annotation to the map, and the above animation trick is designed to work with this. One feature you may want to do if your application heavily relies upon maps, is to create your own custom pins (that don&#8217;t even need to look like pins), to point out specific points on the map.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2010/05/16/mapkit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Redirecting NSLog to a log file</title>
		<link>http://objcolumnist.com/2009/12/19/redirecting-nslog-to-a-log-file/</link>
		<comments>http://objcolumnist.com/2009/12/19/redirecting-nslog-to-a-log-file/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 20:08:18 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=153</guid>
		<description><![CDATA[Using NSLog is all well and good for debugging iPhone OS applications when the device is connected to your Mac, but what about when it is not. Often you want to give builds of your application to people that don&#8217;t have Xcode installed (or can&#8217;t get the silly certificates to work !!!), or just as [...]]]></description>
			<content:encoded><![CDATA[<p>Using NSLog is all well and good for debugging iPhone OS applications when the device is connected to your Mac, but what about when it is not. Often you want to give builds of your application to people that don&#8217;t have Xcode installed (or can&#8217;t get the silly certificates to work !!!), or just as commonly, to test if the application works outside of your lovely office which has a perfect WiFi connection.</p>
<p>When I first thought about this problem, I was thinking along the lines of build a custom log function lets say MagicLog() and this calls a function that saves the string to a file. The problem with this is that I would have to go through all of my code and add MagicLog() to everywhere that I have NSLog(), that seemed a bit to verbose for my liking.</p>
<p>After searching on the internet I found out that (rather obvious) NSLog runs over standard error. This means that you are able to simply redirect standard error to a file using the ANSI function freopen().</p>
<p><code><br />
FILE *freopen(const char *restrict filename, const char *restrict mode, FILE *restrict stream);<br />
</code></p>
<p>http://www.opengroup.org/onlinepubs/000095399/functions/freopen.html</p>
<p>Before we can save NSLog() to a file, we first have to find a place to save it. The best place to do this is the application&#8217;s documents folder. To get this you can use the following code snippet:</p>
<p><code><br />
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);<br />
NSString *documentsDirectory = [paths objectAtIndex:0];<br />
</code></p>
<p>Once we have the documents folder, we need to give a name to the file. To make it easy for me I just name it &#8220;the date&#8221;.log :</p>
<p><code><br />
NSString *fileName =[NSString stringWithFormat:@"%@.log",[NSDate date]];<br />
</code></p>
<p>To make this into a valid path, use the NSString method stringByAppendingPathComponent</p>
<p><code><br />
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];<br />
</code><br />
The last step is to redirect stderr to this file</p>
<p><code><br />
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);<br />
</code></p>
<p>To keep my code maintainable I keep all of this as a function, and I call it in my AppDelegate if I want to turn this functionality on.</p>
<p><code><br />
- (void)redirectNSLogToDocumentFolder{<br />
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);</p>
<p>	NSString *documentsDirectory = [paths objectAtIndex:0];</p>
<p>	NSString *fileName =[NSString stringWithFormat:@"%@.log",[NSDate date]];</p>
<p>	NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];</p>
<p>	freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);<br />
}</p>
<p></code><br />
<strong>Getting the file.</strong></p>
<p>Now that you have logged all the information you need, you will want to get this off of the device. Thankfully this is easy as well. Simply open the organiser in Xcode and select the device that is currently connected to your Mac.</p>
<p>A the bottom of the main pain there is an application section. Open the detail disclosure on the application you want to get the data from, and hit the little download button to the right of the Application Data package. You will be prompted to save this folder to your mac.</p>
<p><strong>Warning:</strong><br />
Writing to the file system on the iPhone is slow, so this will effect the performance of your application. Therefore DO NOT ship an application with this in, or give it to people that can&#8217;t stand poor performance.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2009/12/19/redirecting-nslog-to-a-log-file/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>URL Encoding</title>
		<link>http://objcolumnist.com/2009/10/25/escaping-a-url/</link>
		<comments>http://objcolumnist.com/2009/10/25/escaping-a-url/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 14:27:49 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=137</guid>
		<description><![CDATA[If you have tried to send any information using a GET web request, you would have come across an annoying problem. That annoying problem is making sure that the URL is correctly encoded. At first glance it would seem that the Cocoa Frameworks do this for you, and you would be right &#8230;. well kind [...]]]></description>
			<content:encoded><![CDATA[<p>If you have tried to send any information using a GET web request, you would have come across an annoying problem. That annoying problem is making sure that the URL is correctly encoded.</p>
<p>At first glance it would seem that the Cocoa Frameworks do this for you, and you would be right &#8230;. well kind of.</p>
<p>The issue is that by default most of these methods leave characters such as &#038; = ? within a URL, as they are strictly speaking valid. The problem is that these characters have special meanings in a GET request, and will more than likely make your request in valid.</p>
<p>Luckily there is a function in Core Foundation that helps:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;">CFStringRef CFURLCreateStringByAddingPercentEscapes <span style="color: #002200;">&#40;</span>
   CFAllocatorRef allocator,
   CFStringRef originalString,
   CFStringRef charactersToLeaveUnescaped,
   CFStringRef legalURLCharactersToBeEscaped,
   CFStringEncoding encoding
<span style="color: #002200;">&#41;</span>;</pre></td></tr></table></div>

<p>What makes this function useful, is the <strong>legalURLCharactersToBeEscaped</strong> parameter. This will escape legal characters such as &#038; ? = if they are supplied. This allows you to escape parameters using the following code.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
CFURLCreateStringByAddingPercentEscapes<span style="color: #002200;">&#40;</span>kCFAllocatorDefault, <span style="color: #002200;">&#40;</span>CFStringRef<span style="color: #002200;">&#41;</span>parameter, <span style="color: #a61390;">NULL</span>, CFSTR<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;:/?#[]@!$&amp;’()*+,;=&quot;</span><span style="color: #002200;">&#41;</span>, kCFStringEncodingUTF8<span style="color: #002200;">&#41;</span></pre></td></tr></table></div>

<p>An example of when to use this, is Twitters Update status API. You can find that here http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0update</p>
<p>To update your status to the following:</p>
<p><strong>This is my status</strong></p>
<p>You would need to post up the following URL:</p>
<p>http://twitter.com/statuses/update.xml?status=This%20is%20my%20status</p>
<p>As this is such a common problem of mine, I have created a category on NSURL. This allows you to pass in a base URL and a parameters dictionary.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;">&nbsp;
<span style="color: #002200;">+</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>URLWithBaseString<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>baseString parameters<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>parameters<span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #400080;">NSMutableString</span> <span style="color: #002200;">*</span>urlString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableString</span> <span style="color: #a61390;">string</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #11740a; font-style: italic;">//The URL starts with the base string</span>
<span style="color: #002200;">&#91;</span>urlString appendString<span style="color: #002200;">:</span>baseString<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>escapedString;
&nbsp;
NSInteger keyIndex <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;
&nbsp;
<span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span> key <span style="color: #a61390;">in</span> parameters<span style="color: #002200;">&#41;</span>
 <span style="color: #002200;">&#123;</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">//First Parameter needs to be prefixed with a ? and any other parameter needs to be prefixed with an &amp;</span>
<span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>keyIndex <span style="color: #002200;">==</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#41;</span>
<span style="color: #002200;">&#123;</span>
escapedString <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>CFURLCreateStringByAddingPercentEscapes<span style="color: #002200;">&#40;</span>kCFAllocatorDefault,
 <span style="color: #002200;">&#40;</span>CFStringRef<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>parameters valueForKey<span style="color: #002200;">:</span>key<span style="color: #002200;">&#93;</span>,
 <span style="color: #a61390;">NULL</span>,
 CFSTR<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;:/?#[]@!$&amp;’()*+,;=&quot;</span><span style="color: #002200;">&#41;</span>, 
kCFStringEncodingUTF8<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>urlString appendFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;?%@=%@&quot;</span>,key,escapedString<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>escapedString release<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#125;</span><span style="color: #a61390;">else</span><span style="color: #002200;">&#123;</span>
&nbsp;
escapedString <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>CFURLCreateStringByAddingPercentEscapes<span style="color: #002200;">&#40;</span>kCFAllocatorDefault, 
<span style="color: #002200;">&#40;</span>CFStringRef<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>parameters valueForKey<span style="color: #002200;">:</span>key<span style="color: #002200;">&#93;</span>,
 <span style="color: #a61390;">NULL</span>, 
CFSTR<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;:/?#[]@!$&amp;’()*+,;=&quot;</span><span style="color: #002200;">&#41;</span>,
 kCFStringEncodingUTF8<span style="color: #002200;">&#41;</span>;
&nbsp;
<span style="color: #002200;">&#91;</span>urlString appendFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&amp;%@=%@&quot;</span>,key,escapedString<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>escapedString release<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span>
&nbsp;
keyIndex<span style="color: #002200;">++</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">return</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span>urlString<span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #002200;">&#125;</span></pre></td></tr></table></div>

<p>Using a parameters dictionary keeps the code nice and clean, but beware, to use the category method above you still have to make sure that your keys, and the base URL are correctly encoded (no spaces or invalid characters !!!!!).</p>
<p>As we now have a category method to do all the hard work for us, to create the Twitter URL you just need to do the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>baseString<span style="color: #002200;">=</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://twitter.com/statuses/update.xml&quot;</span>;
&nbsp;
<span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>dictionary<span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDictionary</span> dictionaryWithObjectsAndKeys<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;This is my status&quot;</span>,<span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;status&quot;</span>,<span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>url<span style="color: #002200;">=</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithBaseString<span style="color: #002200;">:</span>baseString parameters<span style="color: #002200;">:</span>dictionary<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

<p>And thats it. Obviously this category can be used for things other than twitter &#8230;.. if you really want to.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2009/10/25/escaping-a-url/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Simple UIView based Animations on the iPhone</title>
		<link>http://objcolumnist.com/2009/07/18/simple-uiview-based-animations-on-the-iphone/</link>
		<comments>http://objcolumnist.com/2009/07/18/simple-uiview-based-animations-on-the-iphone/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 11:33:39 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[CocoaTouch]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=108</guid>
		<description><![CDATA[Although for complex animation sequences on the iPhone you need to use either the OpenGL or Apple&#8217;s very own Core Animation Framework, a lot of simple animations can be achieved with the methods found in the UIView class. All these animations are actually built upon Core Animation, but they have been wrapped up for you [...]]]></description>
			<content:encoded><![CDATA[<p>Although for complex animation sequences on the iPhone you need to use either the OpenGL or Apple&#8217;s very own Core Animation Framework, a lot of simple animations can be achieved with the methods found in the UIView class. All these animations are actually built upon Core Animation, but they have been wrapped up for you to use with very little code.</p>
<p>All animations triggered by the UIView class happen within a animation block.</p>
<p>To start an animation block you use the UIView Class method:<br />
<code><br />
+ (void)beginAnimations:(NSString *)animationID context:(void *)context;<br />
</code></p>
<p>The animation ID is used in delegate call backs for such things as the beginning and end of animation blocks. The context is  an additional piece of information that can be passed through.</p>
<p>As both of these parameters are optional, you comenly see:<br />
<code><br />
[UIView beginAnimations:@"" context:NULL];<br />
</code></p>
<p>To commit these animations, and therefore end the animation block, you need to use the UIView class method:<br />
<code><br />
+ (void)commitAnimations<br />
</code></p>
<p>So what types of animations can you do ? well quite a few.</p>
<p>You can animate views by:</p>
<ul>
<li>Changing their alpha</li>
<li>Changing there size</li>
<li>Changing there location</li>
</ul>
<p>In a single animation block you can animate multiple views, and you are also able to nest animation blocks.</p>
<p>So lets do a common example. When a UITableViewCell is being edited you often want to make a UILabel&#8217;s (label) alpha change to 0 so it is hidden:</p>
<p><code></p>
<p>[UIView beginAnimations:@"" context:NULL];<br />
[label setAlpha:(editing ? 0.0 : 1.0)];<br />
[UIView commitAnimations];</p>
<p></code></p>
<p>For those new to C programming:<br />
<code><br />
(editing ? 0.0 : 1.0)<br />
</code></p>
<p>Is equivlant to:<br />
<code></p>
<p>   if(editing)<br />
   {<br />
         0.0;<br />
   }else{<br />
         1.0;<br />
   }<br />
</code></p>
<p>So for the second example we also have a UILabel (label), that we want to grow when the animation code is run. We also want this animation to last 2 seconds, so the user can admire our work. In addition to this, we want the animation to &#8220;ease in&#8221;. This is known as the animation curve. The animation curves that are available are</p>
<ul>
<li>ease in (slow then fast)</li>
<li>ease out (fast then slow)</li>
<li>ease in and out (slow, fast, slow)</li>
<li>linear (constant speed)</li>
</ul>
<p>We would do this animation using the following animation block:</p>
<p><code></p>
<p>[UIView beginAnimations:@"" context:NULL];</p>
<p>//The new frame size<br />
[label setFrame: CGRectMake(0,0,320,100)];</p>
<p>//The animation duration<br />
[UIView setAnimationDuration:2.0];</p>
<p>[UIView setAnimationDelay: UIViewAnimationCurveEaseIn];</p>
<p>[UIView commitAnimations];</p>
<p></code></p>
<p>This is just a brief overview of the animations you can do using the UIView class, but it should be enough to get you started. The UIView methods also include delegate call backs for when an animation starts and end. For more information see Apple&#8217;s Documentation.</p>
<p>If the UIView class does not have what you need, you will probably need to use the Core Animation framework. While using this framework is not trivial, it is not as hard as using OpenGL (which is used commonly for 3D games), and you can build some fantastic animations using it.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2009/07/18/simple-uiview-based-animations-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Changing the name of an iPhone application</title>
		<link>http://objcolumnist.com/2009/07/04/changing-the-name-of-an-iphone-application/</link>
		<comments>http://objcolumnist.com/2009/07/04/changing-the-name-of-an-iphone-application/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 11:26:10 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Quick Tip]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=105</guid>
		<description><![CDATA[When you finally come to release your application after months of hard work, your might want to change the name of the application that appears on the iPhone springboard, and if you use it, the settings application. To change the name of an iPhone application is very easy. Simply open the Xcode project, and then [...]]]></description>
			<content:encoded><![CDATA[<p>When you finally come to release your application after months of hard work, your might want to change the name of the application that appears on the iPhone springboard, and if you use it, the settings application.</p>
<p>To change the name of an iPhone application is very easy. Simply open the Xcode project, and then scroll down to the &#8220;Targets&#8221; section, which the the &#8220;Groups &#038; Files&#8221; part of Xcode. Select the application&#8217;s target and &#8220;Get info&#8221; on it using cmd-i or ctrl clicking it, and select &#8220;Get Info&#8221; from the menu.</p>
<p>In the build section of the get info window, you need to change the &#8220;Product Name&#8221; value to whatever you want your application to be called. When you change this value make sure that the configuration pop up menu (at the top of the window) is set to &#8220;All Configurations&#8221;, so it takes effect in all of your builds.</p>
<p>For the change of name to take effect, simply clean your targets and rebuild your application.</p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2009/07/04/changing-the-name-of-an-iphone-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Make your iPhone vibrate</title>
		<link>http://objcolumnist.com/2009/05/23/make-your-iphone-vibrate/</link>
		<comments>http://objcolumnist.com/2009/05/23/make-your-iphone-vibrate/#comments</comments>
		<pubDate>Sat, 23 May 2009 20:27:58 +0000</pubDate>
		<dc:creator>Spencer MacDonald</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Quick Tip]]></category>

		<guid isPermaLink="false">http://objcolumnist.com/?p=56</guid>
		<description><![CDATA[One thing that took me a while to find out, was how to make an iPhone vibrate. In the end I found out that it is in the audio APIs, and it is just the one line of code. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);]]></description>
			<content:encoded><![CDATA[<p>One thing that took me a while to find out, was how to make an iPhone vibrate. In the end I found out that it is in the audio APIs, and it is just the one line of code.</p>
<p><code><br />
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://objcolumnist.com/2009/05/23/make-your-iphone-vibrate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

