码迷,mamicode.com
首页 > 其他好文 > 详细

Touch基本

时间:2015-10-07 18:49:59      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

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坐标%fy坐标%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

Touch基本

标签:

原文地址:http://www.cnblogs.com/CoderAlex/p/4859022.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!