*******view 一些方法
#import "HMView.h" @implementation HMView // 一个完整的触摸过程 // touchesBegan -> touchesMoved -> touchesEnded /* NSArray 集合 有序 NSSet 无序 */ // 触摸开始 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // 获取一个UITouch UITouch *touch = [touches anyObject]; // NSLog(@"%s----%d",__func__,touches.count); // NSLog(@"%d",touch.tapCount); // NSLog(@"%d",touch.phase); } // 手指移动 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { // 获取一个UITouch UITouch *touch = [touches anyObject]; // 获取当前的位置 CGPoint current = [touch locationInView:self]; // 获取上一个点 CGPoint pre = [touch previousLocationInView:self]; // x轴偏移量 CGFloat offsetX = current.x - pre.x; CGFloat offsetY = current.y - pre.y; NSLog(@"%@",NSStringFromCGPoint(current)); // 获取视图的center CGPoint center = self.center; center.x += offsetX; center.y += offsetY; self.center = center; } // 触摸结束 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { // 获取一个UITouch UITouch *touch = [touches anyObject]; // NSLog(@"%d",touch.phase); // NSLog(@"%s----%p",__func__,touch); } // 触摸被打断 比如打电话过来 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { } @end
时间: 2025-01-18 09:00:02