触摸(Touch)

来源:互联网 发布:大气监测实时数据 编辑:程序博客网 时间:2024/05/22 05:08

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

/**开始触摸时,记录点击的次数*//**开始触碰会调用*/- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{    /**touches 是个集合 event是哪个类型的事件*/    /**随机取出一个对象*/    UITouch *touch = [touches anyObject];    /**触碰的次数*/    NSLog(@"%d",touch.tapCount);}
/**实现拖动*//**开始移动会调用*/- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{    /**1.随机取出一个对象*/    UITouch *touch = [touches anyObject];    /**2.获取当前的位置*/    CGPoint current = [touch locationInView:self];    NSLog(@"%@",NSStringFromCGPoint(current));    /**3.获取上一外触碰点位置*/    CGPoint previous = [touch previousLocationInView:self];    /**4.修改当前view的位置(中点)*/    CGPoint center = self.center;    center.x += current.x - previous.x;    center.y += current.y - previous.y;    self.center = center;}
0 0
原创粉丝点击