#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];
}
}
本文介绍了一个简单的iOS轻扫手势实现方法。通过监听触摸开始和结束事件,计算触摸位移来判断用户是否进行了轻扫操作,并据此改变视图背景颜色。
833

被折叠的 条评论
为什么被折叠?



