首页 > 代码库 > 对任何视图的手势进行控制

对任何视图的手势进行控制

//对任何视图的手势进行控制 只需要对一下两个方法进行控制

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

{
    if (![gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
        return YES;
    }
    
    CGPoint velocity = [(UIPanGestureRecognizer*)gestureRecognizer velocityInView:self];
    if ((velocity.x == 0) && (velocity.y!= 0)) {
        return YES;
    }
    else if ((velocity.x == 0) && (velocity.y== 0)){
        return NO;
    }
    
    if( fabs(velocity.y / velocity.x) >= tan(M_PI/3)){
        return YES;
    }
    
    return NO;
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return YES;
}