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];

    }

}

posted @ 2014-04-17 09:02  忆轩  阅读(120)  评论(0)    收藏  举报