UIPanGestureRecognizer

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。

时间: 2024-11-05 19:16:10

UIPanGestureRecognizer的相关文章

ios开发——UIPanGestureRecognizer判定方向

有时我们在做拖动功能的时候会用到UIPanGestureRecognizer手势,例如之前封装过的一个侧滑导航栏: ios开发--仿新版QQ侧滑导航栏的实现 今天在用这个导航栏的时候发现一个问题,UIPanGestureRecognizer是任何滑动手势都会辨别,它不像UISwipeGestureRecognizer一样有方向,这样就会导致如果导航栏的MainView不是UIScrollView或者UITableView的话上下滑动会出现视图消失的错误,这是因为上下滑动也会触发手势的响应方法.

1 - 姿势识别器UIPanGestureRecognizer

今天讲一下姿势识别器,UIGestureRecognizer这个是抽象类 1.拍击UITapGestureRecognizer (任意次数的拍击) 2.向里或向外捏UIPinchGestureRecognizer (用于缩放) 3.摇动或者拖拽UIPanGestureRecognizer (拖动) 4.擦碰UISwipeGestureRecognizer (以任意方向) 5.旋转UIRotationGestureRecognizer (手指朝相反方向移动) 6.长按UILongPressGest

UIPanGestureRecognizer方向判断(摘)

#pragma mark滑动手势的识别start typedef enum:NSInteger{ kCameraMoveDirectionNone, kCameraMoveDirectionUp, kCameraMoveDirectionDown, kCameraMoveDirectionRight, kCameraMoveDirectionLeft }CameraMoveDirection;//枚举方向 -(void)panClick:(UIPanGestureRecognizer *) ge

UIPanGestureRecognizer 拖动TableView改变其高度

需求:项目中要求tableView的高度随着手拖动的位置而改变如下图: 关键代码如下: - (void)viewDidLoad{ panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(toHandlePanAction:)]; [self.searchResultView addGestureRecognizer: panGestureRecognizer]; } -

iOS开发--MKMapView添加UIPanGestureRecognizer

当我们想给MKMapView添加拖动手势时,第一个想法可能是这样: - (void)viewDidLoad { //.... UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; [self.mapView addGestureRecognizer:panGesture]; } - (void)handlePan

uiscrollview上的 uipangesturerecognizer冲突

最近在tableview里的cell imageview加了个 uipangesturerecognizer发现优先滚动imageview,往上拖的时候,tableView不响应滚动了,原来是tableview的实现也是用了uipangesturerecognizer.解决方案如下: 实现 UIGestureRecognizerDelegate - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRec

UIPanGestureRecognizer上下左右滑动方向判断算法

CGFloat const gestureMinimumTranslation = 20.0; typedef enum :NSInteger { kCameraMoveDirectionNone, kCameraMoveDirectionUp, kCameraMoveDirectionDown, kCameraMoveDirectionRight, kCameraMoveDirectionLeft } CameraMoveDirection; @interfaceViewController

iOS滑动手势UIPanGestureRecognizer 注意事项

今天在做侧滑页面时,发现页面随着滑动手势而滑动,到临界点时,如果再滑动会出现抖动现象.找到解决办法是进入方法后先判断一次,再判断是在滑动范围内让页面滑动.遂将滑动手势(UIPanGestureRecognizer )注意事项总结了如下: 代码: - (void)panAction:(UIPanGestureRecognizer *)pan{ _canLeft = YES; _canRight = YES; //点相对于上一个点的位置 CGPoint moviePoint = [pan trans

UITapGestureRecognizer 和UIPanGestureRecognizer的使用,触摸和滑动

/** *  点击了进度条背景 */ - (IBAction)tapProgressBg:(UITapGestureRecognizer *)sender { CGPoint point = [sender locationInView:sender.view]; // 切换歌曲的当前播放时间 self.player.currentTime = (point.x / sender.view.width) * self.player.duration; [self updateCurrentTim

UIPanGestureRecognizer类中translationInView

UIPanGestureRecognizer主要用于拖动,比如桌面上有一张图片uiimageview,你想让它由原始位置拖到任何一个位置,就是图片跟着你的手指走动,那么就需要用到该类了. 以下代码表示给一个图片视图指定一个UIPanGestureRecognizer手势当该图片捕获到用户的拖动手势时会调用回调函数handlePan C代码   UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget: