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

UIPanGestureRecognizer

时间:2014-09-22 19:04:23      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   for   div   sp   cti   on   

Configuring the Gesture Recognizer

@property(nonatomic) NSUInteger maximumNumberOfTouches//The maximum number of fingers that can be touching the view for this gesture to be recognized.
@property(nonatomic) NSUInteger minimumNumberOfTouches//The minimum number of fingers that can be touching the view for this gesture to be recognized.

 

Tracking the Location and Velocity of the Gesture

- (CGPoint)translationInView:(UIView *)view//The translation of the pan gesture in the coordinate system of the specified view.平移的距离。设置后速度为0.
- (void)setTranslation:(CGPoint)translation inView:(UIView *)view//设置平移的距离
- (CGPoint)velocityInView:(UIView *)view//速度。 which is expressed in points per second.

 

例子

方法1:

    CGFloat translationX = [pan translationInView:self.view].x;
    pan.view.center = CGPointMake(pan.view.center.x+translationX, pan.view.center.y);
    [pan setTranslation:CGPointZero inView:self.view];

方法2:

CGPoint translation = [recognizer translationInView:recognizer.view];

case UIGestureRecognizerStateBegan: {
            [recognizer setTranslation:CGPointMake(recognizer.view.frame.origin.x, 0) inView:recognizer.view];
            break;
        }
        case UIGestureRecognizerStateChanged: {
            [recognizer.view setTransform:CGAffineTransformMakeTranslation(MAX(0,translation.x), 0)];            
            [self statusBarView].transform = recognizer.view.transform;
            break;
        }

 

目前看来,translationInView的参数是attach的view还是其父view关系不大。每次的translation都是与上次的叠加。因此如果每次设置为0,则累加坐标即可。否则要用setTransform。

UIPanGestureRecognizer

标签:style   blog   io   ar   for   div   sp   cti   on   

原文地址:http://www.cnblogs.com/zhongriqianqian/p/3986322.html

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