BFDragGestureRecognizer 1.1.0

BFDragGestureRecognizer 1.1.0

测试已测试
语言语言 Obj-CObjective C
许可协议 BSD
发布时间上次发布2014年12月

Balazs Faludi 维护。




  • Balazs Faludi

image

摘要

BFDragGestureRecognizer 是一个 UIGestureRecognizer 子类,可用于在滚动视图内部拖动视图,同时在滚动视图边缘自动滚动。

说明

如果没有 Podfile,请创建一个。添加以下行。

pod 'BFDragGestureRecognizer'

运行以下命令。

pod install

或者,您可以将 BFDragGestureRecognizer.{h,m} 文件直接拖放到您的项目中。

将手势识别器添加到您想拖动视图的视图

BFDragGestureRecognizer *dragRecognizer = [[BFDragGestureRecognizer alloc] init];
[dragRecognizer addTarget:self action:@selector(dragRecognized:)];
[view addGestureRecognizer:dragRecognizer];

实现手势处理方法。这与使用标准的 UIPanGestureRecognizer 做的非常类似

- (void)dragRecognized:(BFDragGestureRecognizer *)recognizer {
    UIView *view = recognizer.view;
    if (recognizer.state == UIGestureRecognizerStateBegan) {
        // When the gesture starts, remember the current position.
        _startCenter = view.center;
    } else if (recognizer.state == UIGestureRecognizerStateChanged) {
        // During the gesture, we just add the gesture's translation to the saved original position.
        // The translation will account for the changes in contentOffset caused by auto-scrolling.
        CGPoint translation = [recognizer translationInView:_contentView];
        CGPoint center = CGPointMake(_startCenter.x + translation.x, 
                                     _startCenter.y + translation.y);
        view.center = center;
    } 
}

许可协议

新 BSD 许可协议。完整许可协议文本请见此处