IOS 触屏扫动实例

作者:朱克锋

邮箱:[email protected]

转载请注明出处:http://blog.csdn.net/linux_zkf


#define kMinimumGestureLength    30

#define kMaximumVariance         10


#pragma mark -

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];

    gestureStartPoint = [touch locationInView:self.view];

}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];

    CGPoint currentPosition = [touch locationInView:self.view];

    CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);

    CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);

    if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) {

        NSLog(@"Horizontal");

    }

    else if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){

        NSLog(@"Vertical");

    }

}

你可能感兴趣的:(ios)