Vladimir Putin “We discussed this important issue yesterday over a beer...”

Barack OBAMA “You know, my faith is one that admits some doubt...”




How image moves with touch function in the iPad

Posted by admin on Apr 8th, 2011 and filed under Iphone and Ipad. You can follow any responses to this entry through the RSS 2.0. Responses are currently closed, but you can trackback from your own site.



In this application we will see to the image as moved, with touch function we where everyone on the screen moves.

Step 1: Create a view-based application with template. Enter the name of “Rotateimage”.

Step 2: Xcode automatically creates the directory structure and essential framework adds. You can explore the directory structure to verify the contents of the directory.

Step 3: Xpand created classes and Interface Builder notice the RotateImageViewController class for you. Expand resources and note that the template generates a separate nib, RotateImageViewController.xib for the “RotateImage”.

Step 4: We must add UIView class in your project. SELECT classes-> add new file-> cocoa touch class-> objective C class-> select UIView from the subclass of->. Type the file name “Imageview”.

Step 5: We have added a resource in the resources folder. Enter the name of the resource “1.png”.

Step 6: Specified in the ImageView.h file of the parent class as a UIImageView. So you take the following changes to the file:

# Import
@ Interface ImageView: UIImageView {}
}

Step 7: Open the file ImageView.m, make the following modifications to the file.

-(Id) image InitWithImage:(UIImage_*) {}
If (self = [super InitWithImage: image]) {}
[Self SetUserInteractionEnabled: YES];
[Self SetMultipleTouchEnabled: YES];
} return self;
}

-(void) TouchesMoved:(NSSet_*) WithEvent:(UIEvent_*) event touches
{
If ([count touched] == 1) {}
CGPoint NewTouch = [[touches AnyObject] LocationInView: [self Superview]];
CGPoint load touch = [[touches AnyObject] PreviousLocationInView: [self Superview]];
float xDif = newTouch.x – lastTouch.x;
float yDif = newTouch.y – lastTouch.y;
Translate CGAffineTransform = CGAffineTransformMakeTranslation (xDif, yDif);
[Self set transform: CGAffineTransformConcat (translate [self transformation])];
}
}

Step 8: Where the RotateImageViewController.h file, we have “ImageView.h” file import.

Step 9: Open the RotateImageViewController.m file, we create a ImageView and make them visible. So you take the following changes to the file.

Games (void) {}
[super games];
ImageView * ImageView = [[ImageView alloc] InitWithImage: [UIImage imageNamed:@"1.png]” “];
[ImageView set frame: CGRectMake(110,_180,_[imageView_frame].size.width,[imageView_frame].size.height)];
[[Self view] AddSubview: imageView];
[ImageView release];
}

Step 10: Now compile and run the application in the Simulator.

You can Download source code from here RotateImage

Share

Comments are closed

Advertisement
Free WordPress Theme