The below code provides the direction of the swipe between two points:



+(int) getDirectionBetweenFirst:(CGPoint)point1 secondPoint:(CGPoint)point2 {
    
    DIRECTION_TYPE directionType = CLOCKWISE;
    
    if (point1.x < point2.x  ) {
        
        if(point1.y > point2.y){
            
            directionType = CLOCKWISE;
            
        }else if(point1.y < point2.y)
        {
            directionType = COUNTERCLOCKWISE;
            
        }else{
            
            if(point1.y <= kCenterYCoordinate){
                directionType = CLOCKWISE;
            }else{
                directionType = COUNTERCLOCKWISE;
                
            }
      
        }
    }
    else if(point1.x > point2.x  ){
        
        if(point1.y > point2.y){
             directionType = COUNTERCLOCKWISE;
        }else if(point1.y < point2.y)
        {
            directionType = CLOCKWISE;
            
        }
        else{
            
            if(point1.y <= kCenterYCoordinate){
                directionType = COUNTERCLOCKWISE;
            }else{
                directionType = CLOCKWISE;
                
            }
        }
    }else{
        
        if (point1.y < point2.y) {
            
            if(point1.x <= kCenterXCoordinate){
                directionType = COUNTERCLOCKWISE;
            }else{
                directionType = CLOCKWISE;
                
            }
        }else if(point1.y > point2.y){
            
            if(point1.x <= kCenterXCoordinate){
                directionType = CLOCKWISE;
            }else{
                directionType = COUNTERCLOCKWISE;
                
            }
        }
        
    }
   
    return directionType;
}


kCenterYCoordinate and kCenterXCoordinate are center point of the UIView on which you detect your touches.

Advertisements