How to Move Image using Touch Function in iPhone?

This is the very simple application. In this application we will see how to image move using touch. So let see how it will work.

Step 1 : Open the Xcode, Create a new project using View Base application. Give the application “Touch_Image”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: We need add also two resource in the project.

Step 4: In the Touch_ImageViewController.h file, make the following changes.

#import <UIKit/UIKit.h> 

@interface Touch_ImageViewController : UIViewController {
UIImageView *image;
@property (nonatomic,retain) IBOutlet UIImageView *image;

Step 5: Double click the Touch_ImageViewController.xib file and open it to the interface builder. First select the view and bring up Attribute Inspector and change the background color. Drag the label from the library and place it to the view window. Select the label and bring up Attributes Inspector and the text to “Touch Anywhere” . Now drag the ImageView from the library and place it to the view window. Select the Image View from the view and bring up Attribute Inspector and select the litchi-big.png image. Connect File’s Owner icon to the image view and select image. Now save the .xib file, save it and go back to the Xcode.

Step 6: Open the Touch_ImageViewController.m file and make the following changes:

#import “Touch_ImageViewController.h” 

@implementation Touch_ImageViewController

@synthesize image;

– (void)dealloc
[super dealloc];

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event

UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:touch.view]; = touchLocation;

– (void)didReceiveMemoryWarning

[super didReceiveMemoryWarning];


#pragma mark – View lifecycle

– (void)viewDidUnload
[super viewDidUnload];

return (interfaceOrientation == UIInterfaceOrientationPortrait);



Step 7: Now compile and run the application on the Simulator.


iOS5 – how to turn off ARC on individual files ?

iOS5 SDK comes with new feature of ARC.

ARC = Automatic Reference Counting which is used for enabling memory management at compiler level.


But due to this feature, you might not able to compile facebook API, HJCache library or any other libraries developed for iPhone/iPad development.

Here is the one of the example of that error.

Automatic Reference Counting forbids explicit message send of ‘dealloc’

I have shared a trick to enable older library compilation in new iOS5 SDK.

  1. Click on the Project.
  2. Click on the target.
  3. Select build phases tab.
  4. Select the multiple files in which you want to turn off ARC.
  5. Press ENTER / Hit Enter key
  6. Type “-fno-objc-arc” ( without quotes, as shown in image )
I hope this might be helpful to you.
Please let me know your comments for this.
Thanks & Regards,
Ankit Vyas