Touch系统主要有一下几种方法
//懒加载
- (UIImageView *)imageView{
if (!_imageView) {
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 70, self.view.bounds.size.width-40, self.view.bounds.size.height/2)];
_imageView.image = [UIImage imageNamed:@"1.jpg"];
}
return _imageView;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.imageView];//名字和懒加载名字要相同,相当于调用方法
}
//NSSet,跟数组差不多,只不过NSSet集合中不能存放相同的元素,并且存入到集合中的元素是无序的
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
_imageView.frame = self.view.bounds;
//不间断时间内连续点击次数
UITouch *touch = [touches anyObject];
NSLog(@"tapCount = %lu",touch.tapCount);
NSLog(@"touch.timestamp = %f",touch.timestamp);
NSLog(@"%lu",event.allTouches.count);//手指数
//找出(单一)手指在屏幕的位置
CGPoint point = [touch locationInView:self.view];
NSLog(@"%@",NSStringFromCGPoint(point));//[NSValue valueWithCGPoint:point];
// NSLog(@"开始");
//遍历allTouches(集合),把所有手指坐标都打印出来
for (UITouch *t in event.allTouches) {
CGPoint point = [t locationInView:self.view];
NSLog(@"%@",NSStringFromCGPoint(point));
}
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"移动");
for (UITouch *t in event.allTouches) {
CGPoint point = [t locationInView:self.view];
NSLog(@"%@",NSStringFromCGPoint(point));
}
}
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"取消");
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
_imageView.frame = CGRectMake(50, 100, self.view.bounds.size.width-100, self.view.bounds.size.height/2);
NSLog(@"结束");
}