Home Tutorial Iphone Examples iphone Touch Image

 
 

iphone Touch Image
Posted on: September 23, 2009 at 12:00 AM
Advertisement
In this tutorial, will learn how to use Image View in the application and also how to set the image on the Image View and then will see how the image moves when we click the cursor on the screen.

iphone Touch Image

In this tutorial, will learn how to use Image View in the application and also how to set the image on the Image View and then will see how the image moves when we click the cursor on the screen. This application will be based on View Based Application and the code will write it in view controller file, will declare the variables into the .h file and the action of that method will be written in .m file. 

Final view will look like this:

Here will declare an variable for the image View, so that we can set the image on Image View after that will use this variable into .m file for the method that when the user clicks anywhere on the screen the image will move to the place where the user clicked. To do this the method used is touchesBegan: withEvent: and after that get touch event, and then get the touch location and then to move the image view using the variable of Image View.

Add this to ViewController.h file:

IBOutlet UIImageView *movingImg;

Add this to ViewController.m file:

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

{

    // get touch event

    UITouch *touch = [[event allTouches] anyObject];

    // get the touch location

    CGPoint touchLocation = [touch locationInView:touch.view];

    // move the image view

    movingImg.center = touchLocation;

}

Make connections and also set the image on Image View:

Finally Press Build And Go Button

Download Here

Advertisement

Related Tags for iphone Touch Image:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 23, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com