<?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>iPhone Programming Tutorials &#187; UIImageView</title>
	<atom:link href="/tag/uiimageview/feed/" rel="self" type="application/rss+xml" />
	<link>http://icodeblog.com</link>
	<description>Conquering the mobile universe</description>
	<lastBuildDate>Tue, 28 Jun 2011 21:44:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>iPhone Programming Tutorial – Animating a Ball Using An NSTimer</title>
		<link>http://icodeblog.com/2008/10/28/iphone-programming-tutorial-animating-a-ball-using-an-nstimer/</link>
		<comments>http://icodeblog.com/2008/10/28/iphone-programming-tutorial-animating-a-ball-using-an-nstimer/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 14:44:06 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[iphone programming]]></category>
		<category><![CDATA[iphone tutorial]]></category>
		<category><![CDATA[NSTimer]]></category>
		<category><![CDATA[UIImageView]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=523</guid>
		<description><![CDATA[I have noticed recently many people wanting to create games for the iPhone and are unsure where to start.  A common misconception is that you must use OpenGL ES to create any game with graphics.  I am going to show you today how you can do some simple animation by moving a ball around the screen.  We will not be using OpenGL ES to move the ball.  We will simply be using an NSTimer and a UIImageView.
The code for this  ...]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-529" style="display:none;" title="intro" src="/wp-content/uploads/2008/10/intro-300x187.png" alt="" width="300" height="187" />I have noticed recently many people wanting to create games for the iPhone and are unsure where to start.  A common misconception is that you must use OpenGL ES to create any game with graphics.  I am going to show you today how you can do some simple animation by moving a ball around the screen.  We will not be using OpenGL ES to move the ball.  We will simply be using an NSTimer and a UIImageView.</p>
<p>The code for this could be used in many game applications.  Games such as pong, brick breaker, etc&#8230; I will soon do an iPhone game programming tutorial series.  For now, here is a quick tutorial to get you started and excited&#8230;</p>
<p>You will need to download this image for this tutorial:</p>
<p><a href="http://staging.icodeblog.com/wp-content/uploads/2008/10/ball1.png"><img class="alignnone size-full wp-image-525" title="ball" src="http://staging.icodeblog.com/wp-content/uploads/2008/10/ball1.png" alt="" width="32" height="32" /></a></p>
<p>[qt:http://icodeblog.com/wp-content/uploads/2008/10/Animation.mov 640 416]</p>
<p>Here are the steps involved in creating this application:</p>
<h2>Start With a View-Based Application</h2>
<p>We will not need any navigation components for this app.  All we need is a view that we can add a UIImageView to.</p>
<h2>Add The Ball Image To Your Project</h2>
<p>You can use any image you would like for this.  I used my mad skills in Photoshop to create a shiny red ball for you to use.  This will be the image that we will be &#8220;bouncing&#8221; around the screen.</p>
<h2>Add An IBOutlet For the Ball</h2>
<p>This step is necessary as it allows us the link the ball we add to the view in Interface Builder to the code.  This is so we can update the position of the ball at each timestep.</p>
<h2>Add The Ball To The View In Interface Builder</h2>
<p>All we need to draw the ball on the screen is a UIImageView.  Since we added the ball.png file to our project, it should appear in the drop-down in the attributes section of the UIImageView.  Also, at this step, we need to connect the UIImageView to the &#8216;ball&#8217; variable by dragging from &#8216;new referencing outlet&#8217; in the connection inspector of the UIImageView to the &#8216;File&#8217;s Owner&#8217; object.</p>
<h2>Add The Code To Initialize The NSTimer</h2>
<p>An NSTimer is very simple to use.  It simple requires that you specify an interval (I used .05) and a function to call at each time-step.  The function we are calling in this tutorial is the onTimer function.  This is a function that we create and will contain the logic to move the ball.</p>
<h2>Moving The Ball</h2>
<p>This code is all fairly straight forward.  First we add the pos.x and pos.y values (14.0 and 7.0) to the center of the ball object this causes the ball to move diagonally.  Next we simply check to see if the ball has collided with the wall.  If the ball does collide with the wall, we simple reverse the pos.x or the pos.y.</p>
<p>That concludes the animation tutorial.  I hope that you go out an make lots of great games after this&#8230; Soon, I will start another tutorial series where I we will be creating a full blown game.  If you have any suggestions for games, please leave them in the comments.  Make sure that they are fun but not too in depth, we need to limit the series.  Think in terms of pong, asteroids, etc&#8230;</p>
<p>You can download the source code <a href="http://staging.icodeblog.com/wp-content/uploads/2008/10/ball1.zip">here</a> .  If you have any comments or questions, feel free to leave them in the comments of this post.  You may also post them in the <a href="/forum">forums</a>. Happy iCoding!</p>
]]></content:encoded>
			<wfw:commentRss>http://icodeblog.com/2008/10/28/iphone-programming-tutorial-animating-a-ball-using-an-nstimer/feed/</wfw:commentRss>
		<slash:comments>91</slash:comments>
<enclosure url="http://icodeblog.com/wp-content/uploads/2008/10/Animation.mov" length="19459984" type="video/quicktime" />
<enclosure url="http://icodeblog.com/wp-content/uploads/2008/10/Animation.mov" length="19459984" type="video/quicktime" />
		</item>
		<item>
		<title>iPhone Programming Tutorial – Using UITouch To Drag An Image Around The Screen</title>
		<link>http://icodeblog.com/2008/10/20/iphone-programming-tutorial-using-uitouch-to-drag-an-image-around-the-screen/</link>
		<comments>http://icodeblog.com/2008/10/20/iphone-programming-tutorial-using-uitouch-to-drag-an-image-around-the-screen/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 07:00:18 +0000</pubDate>
		<dc:creator>brandontreb</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[iPhone app development]]></category>
		<category><![CDATA[iPhone Coding]]></category>
		<category><![CDATA[iphone programming]]></category>
		<category><![CDATA[UIImageView]]></category>
		<category><![CDATA[UIImageView Tutorial]]></category>
		<category><![CDATA[UITouch]]></category>

		<guid isPermaLink="false">http://icodeblog.com/?p=505</guid>
		<description><![CDATA[

[qt:http://icodeblog.com/wp-content/uploads/2008/10/UITouch.mov 640 416]
In this tutorial, I will be showing you how to use UITouch to get the location of where a user touches on the screen.  We will be using this knowledge to drag a UIImageView around.
Learning how to use UITouch is the first steps in creating applications that are not navigation based (or don&#8217;t only use Apple&#8217;s built in components.  Later on, we will begin some basic game development that will utilize UITouch.
You will need this image for the  ...]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
digg_url = 'http://digg.com/apple/iPhone_Programming_Tutorial_Using_UITouch_To_Drag_An_Image';
// --></script><script src="http://digg.com/api/diggthis.js"></script></p>
<p><img class="alignnone size-full wp-image-507" style="display:none;" title="uitouch" src="http://staging.icodeblog.com/wp-content/uploads/2008/10/uitouch1.png" alt="" width="400" height="250" /></p>
<p>[qt:http://icodeblog.com/wp-content/uploads/2008/10/UITouch.mov 640 416]</p>
<p>In this tutorial, I will be showing you how to use UITouch to get the location of where a user touches on the screen.  We will be using this knowledge to drag a UIImageView around.</p>
<p>Learning how to use UITouch is the first steps in creating applications that are not navigation based (or don&#8217;t only use Apple&#8217;s built in components.  Later on, we will begin some basic game development that will utilize UITouch.</p>
<p>You will need this image for the tutorial</p>
<p style="text-align: center;"><a href="http://staging.icodeblog.com/wp-content/uploads/2008/10/cloud1.png"><img class="alignnone size-full wp-image-509" title="Cloud.png" src="http://staging.icodeblog.com/wp-content/uploads/2008/10/cloud1.png" alt="" width="100" height="100" /></a></p>
<p>In this tutorial, we will perform the following tasks:</p>
<h2>Adding An Image To The Project</h2>
<p>Adding images to your projects is very simple.  All you do is drag them from some folder into your project&#8217;s directory in XCode.  XCode will prompt you to add the image to the project and will also ask you if you want to copy the image to the project&#8217;s directory.  You can use images for a variety of things in XCode. From inserting them in to UIImageViews to using them for UITabBarItems.</p>
<h2>Declaring an IBOutlet for the Image</h2>
<p>We create an IBOutlet for the UIImageView so that we can interface with it.  This will allow the code to send messages to the interface.  In this example, we need this to move the image to the location of the touch.</p>
<h2>Adding a UIImageView</h2>
<p>UIImageViews serve one purpose, and that is to hold an image.  After dragging one on to your view, populating it with an image is easy.  Any images that you have added to your project will show up in the &#8220;Image Dropdown&#8221; under the Attributes Inspector section for the UIImageView.  Simply select one of these images and watch it appear in your view.</p>
<h2>Connect The UIImageView to the IBOutlet</h2>
<p>This is the step that connects interface to code.  We simple drag from &#8220;new referencing outlet&#8221; to the &#8220;File&#8217;s Owner&#8221; object and click on the word &#8220;cloud&#8221;.  The connection has been made.</p>
<h2>Implement the TouchesBegan Method</h2>
<p>In this step, we are overriding a method that Apple has already created so that we can add our own functionality.  This method will automatically get called every time the user touches inside of the view.  Notices that it takes an NSSet of touches.  This is a set contains information about every touch on the screen.  So if the uses touches the screen with 2 fingers, this set will contain two touch objects.  For this tutorial we are only interested in one.</p>
<p>Once we get the touch location, we set the center of the image to that location.  The image will now move to any spot that gets touched.</p>
<h2>Implement The TouchesMoved Event</h2>
<p>This method must be implemented because TouchesBegan only gets called one time when the user touches the screen.  TouchesMoved gets called every time the user &#8220;drags&#8221; their finger around.  To not duplication code, we just told this method to call the TouchesBegan method because we already wrote all of the movement code in it.</p>
<p>Thank you for reading this tutorial.  If you have any questions or comments, feel free to leave them in the comments section of this post.  You can also download the sample code <a href="http://staging.icodeblog.com/wp-content/uploads/2008/10/uitouchtutorial1.zip">here</a>.  Also, if you haven&#8217;t already done so, <a href="http://feeds.feedburner.com/icodeblog">subscribe to the RSS feed here</a> as I will be adding new tutorials at least once a week.  Happy iCoding!</p>
]]></content:encoded>
			<wfw:commentRss>http://icodeblog.com/2008/10/20/iphone-programming-tutorial-using-uitouch-to-drag-an-image-around-the-screen/feed/</wfw:commentRss>
		<slash:comments>56</slash:comments>
<enclosure url="http://icodeblog.com/wp-content/uploads/2008/10/UITouch.mov" length="21049220" type="video/quicktime" />
<enclosure url="http://icodeblog.com/wp-content/uploads/2008/10/UITouch.mov" length="21049220" type="video/quicktime" />
		</item>
	</channel>
</rss>
