My App deals with an imageview and I want to drag the image all over the view by means of touches.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{ // This gets you starting position of
UITouch *touch = [ [ event allTouches ] anyObject ] ;
float touchXBeginPoint = [ touch locationInView:touch.view ].x ;
float touchYBeginPoint = [ touch locationInView:touch.view ].y ;
// Calculate the offset between the current image center and the touched points.
touchOffset = hairImage.center.x - touchXBeginPoint;
touchOffset1=hairImage.center.y-touchYBeginPoint;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [ [ event allTouches ] anyObject ] ;
float distanceMoved =( [ touch locationInView:touch.view ].x + touchOffset ) - hairImage.center.x ;
float distanceMoved1=([touch locationInView:touch.view].y+touchOffset)-hairImage.center.y;
float newX = hairImage.center.x + distanceMoved;//+distanceMoved1 ;
float newY=hairImage.center.y+distanceMoved1;
if( newX > 70 && newX < 150 ){ // setting the boundaries
hairImage.center = CGPointMake(newX, hairImage.center.y) ;}
if(newY>100 && newY<180){
hairImage.center=CGPointMake(newY, hairImage.center.x);
}}
This is the code. Here I can move the imageview successfully along X direction, but my target is to move imageview all over the view.
Bit more info on your question helps...like what you have tried, where you got stuck etc..Anyway I just copy pasted the question of your title and googled..Here is the first result