UIviewController可以放入touch事件
UITouch的状态:
//用户刚触摸屏幕时
UITouchPhaseBegin
//表示有触摸在屏幕上移动
UITouchPhaseMoved
//表示触摸仍停留在屏幕表面,不过之前一个事件之后没移动过
UITouchPhaseStationary
//在触摸远离屏幕时被触发
UITouchPhaseEnded
//在IOS系统停止跟踪特定触摸时发生,例如有电话打来
UITouchPhaseCancelled
//touch开始
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
//touch移动
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
//touch结束
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
//touch改变后
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
获取当前touch
UITouch *touch = [touches anyObject];
获取touch坐标
CGPoint currentPoint = [touch locationInView:self];
开启多点触控
self.multipleTouchEnabled = YES;
手势
//轻击
UITapGestureRecognizer 次数 numberOfTapsRequired
//捏合
UIPinchGestureRecognizer
//扫动
UISwipeGestureRecognizer 滑动方向 direction
//长按
UILongPressGestureRecognizer 按住时间minimumPressDuration
//拖动
UIPanGestureRecognizer
UIPanGestureRecognizer *pan = (UIPanGestureRecognizer *)touch;
UIView * view = pan.view;
if (pan.state == UIGestureRecognizerStateBegan || pan.state == UIGestureRecognizerStateChanged)
{
[[selfsuperview] bringSubviewToFront:self];
//获得每次与上次的点的移动距离
CGPoint translation = [pan translationInView:view.superview];
NSLog(@"x坐标%f,y坐标%f",translation.x,translation.y);
[view setCenter:CGPointMake(view.center.x+translation.x, view.center.y + translation.y)];
[pan setTranslation:CGPointZero inView:view.superview];
UIPan