觸摸開始
// 當手指開始觸摸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
{
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。