触摸开始
// 当手指开始触摸view
// NSArray,字典,NSSet(无序)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"%ld", touches.count);
NSLog(@"%s",__func__);
}
触摸移动的时候调用
// 当手指在view上移动的时候
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
// 获取当前点
CGPoint currentPoint = [touch locationInView:self];
// 获取上一个点
CGPoint previousPoint = [touch previousLocationInView:self];
// 获取 X 轴的偏移量
CGFloat x = currentPoint.x - previousPoint.x;
// 获取 Y 轴的偏移量
CGFloat y = currentPoint.y - previousPoint.y;
// 修改 view 的位置
self.transform = CGAffineTransformTranslate(self.transform, x, y);
}
触摸事件被打断的时候
// 当触摸事件被打断的时候调用(电话打入)
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
}