2

I created a simple app that drags an object any where on the screen, It's great but my issue is when I drag on the screen without touching the object it's position changes to the top corner of the screen, but what I need is to drag the object by touching it and moving it any where, not moving my finger on the screen and the object moved to the top corner, here is my code:

  1. the .h file.

    @interface ViewController : UIViewController {
    @property (retain, nonatomic) IBOutlet UIImageView *ball;
      }
    @end        
    
  2. the .m file

    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
    {
    UITouch *userTouch = [[event touchesForView:_ball] anyObject];
    _ball.center = [userTouch locationInView:self.view];
       }
    

So how to fix that issue?

4

1 回答 1

3

您需要使用的是应用于对象本身的 UIPanGestureRecognizer。是一个很好的教程。

于 2013-08-29T23:42:26.480 回答