Touch实现轻扫

#pragma mark - 轻扫

// 开始点击

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

{   

    UITouch *touch = [touches anyObject];

    _startPoint = [touch locationInView:self];    

}

//

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [touches anyObject];

    CGPoint endPoint = [touch locationInView:self];

    CGFloat dltX = endPoint.x - _startPoint.x;

    CGFloat dltY = endPoint.y - _startPoint.y;

    if (dltX > 60 && fabs(dltY) < 20) {

        self.backgroundColor = [UIColorredColor];

    }else if (dltX < -60 && fabs(dltY) < 20)

    {

        self.backgroundColor = [UIColorgreenColor];

    }

}

原文地址:https://www.cnblogs.com/NatureZhang/p/3669938.html