IOS How to drag an image around the screen

This is what I do to drag an image around the screen: 
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] 
                           initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[imageView_ addGestureRecognizer:panRecognizer];
And then: 
-(void)move:(id)sender {

    CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender 
                                             translationInView:self.view];

    if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {

        firstX = [[sender view] center].x;
        firstY = [[sender view] center].y;
    }

    translatedPoint = CGPointMake(firstX+translatedPoint.x, firstY+translatedPoint.y);
    [[sender view] setCenter:translatedPoint];

}

Comments

Popular posts from this blog

LINUX Move and copy files using SSH

PHP Predefined Variables

Java : Variables Declaring