Imagine that i drag an ImageView in TouchesMoved,how can i recognize that in which direction i drag开发者_如何学Pythonged it from code ?
You can store a temporary Point from touchesBegan. Add a iVar in "YourImageView" interface.
@interface YourImageView : UIImageView
{
    CGPoint previousPt;
    //Other iVars.
}
@end 
@implementation YourImageView
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{   
    previousPt = [[touches anyObject] locationInView:self.view];
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    const CGPoint p = [[touches anyObject] locationInView:self.view];
    if (previousPt.x > p.x)
    {
        //Dragged right to left
    }
    else if  (previousPt.x < p.x)
    {
        //Dragged left to right
    }
    else
    {
        //no move
    }
    //Do the same thing for y-direction
}
I would extract a method out of it. But I hope you got the idea.
If you subtract the old position from the new position of the ImageView, then you will get a direction vector. If you want a unit vector, just normalize it.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论