UIImageView *_imageView;
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 30, 100, 100)];
UIImage *image = [UIImage imageNamed:@"agent_40"];
_imageView.image = image;
//手指触碰到屏幕的时候触发
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"began");
}
//手指移动的时候触发
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//UITouch 一个触摸点
UITouch *th = [touches anyObject]; //取出任意一个点
//将touch转换为一个具体的坐标点
CGPoint currentLocation = [th locationInView:self.view];
//获取上一个坐标点
// CGPoint perviousLocation = [th previousLocationInView:self.view];
_imageView.center = currentLocation;
NSLog(@"move.. %@", NSStringFromCGPoint(currentLocation));
}
//所有手指离开屏幕的时候触发
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"end");
}
//被中断的时候触发
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"cancelled");
}