触摸事件

新建一个uiView  设置类名 

 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
//NSLog(@"%s",__func__);
// 获取当前触摸点的UITouch对象
UITouch *touch = [touches anyObject];

//获取 当前触摸的位置
CGPoint current = [touch locationInView:touch.view];

//获取 触摸前的位置
CGPoint previous = [touch previousLocationInView:touch.view];

NSLog(@"触摸前的点: %@ 当前触摸点:%@",NSStringFromCGPoint(previous), NSStringFromCGPoint(current));

// 改变位置
CGPoint center = self.center;
center.x += current.x - previous.x;
center.y += current.y - previous.y;

self.center = center;

}

posted on 2015-12-05 10:33  窗外美景  阅读(110)  评论(0)    收藏  举报