`

View GestureRecognizer

 
阅读更多
http://hi.baidu.com/bunsman/blog/item/1b1930de4e43a74895ee3756.html
http://hi.baidu.com/%B0%D9ii%D6%AAi%B5%C0/blog/item/04bfba11fb47a2c5f7039ea8.html
http://blog.csdn.net/pjk1129/article/details/6824810


UIResponder 响应者链
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;


长按View
UILongPressGestureRecognizer *longPressGR = 
        [[UILongPressGestureRecognizer alloc] initWithTarget:self 
                                                      action:@selector(handleLongPress:)];
        longPressGR.minimumPressDuration = 0.2;
        [self addGestureRecognizer:longPressGR];
        [longPressGR release];


- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer {
    NSLog(@"LONG PRESS");
}


如果双击确定偵測失败才會触发单击
    [singleRecognizer requireGestureRecognizerToFail:doubleRecognizer];

@protocol UIGestureRecognizerDelegate <NSObject>
@optional
// called when a gesture recognizer attempts to transition out of UIGestureRecognizerStatePossible. returning NO causes it to transition to UIGestureRecognizerStateFailed
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;

// called when the recognition of one of gestureRecognizer or otherGestureRecognizer would be blocked by the other
// return YES to allow both to recognize simultaneously. the default implementation returns NO (by default no two gestures can be recognized simultaneously)
//
// note: returning YES is guaranteed to allow simultaneous recognition. returning NO is not guaranteed to prevent simultaneous recognition, as the other gesture's delegate may return YES
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;

// called before touchesBegan:withEvent: is called on the gesture recognizer for a new touch. return NO to prevent the gesture recognizer from seeing this touch
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;

@end



UITapGestureRecognizer 点击动作
UIPinchGestureRecognizer 捏/掐动作
UIRotationGestureRecognizer 旋转动作
UISwipeGestureRecognizer 轻扫动作
UIPanGestureRecognizer 平移动作
UILongPressGestureRecognizer 长按动作
分享到:
评论

相关推荐

    gestureRecognizer

    手势识别(GestureRecognizer)是iOS开发中的重要组成部分,它允许用户通过特定的手势与应用程序进行交互。在iOS系统中,UIKit框架提供了多种内置的手势识别器类,如UIPanGestureRecognizer(拖动)、...

    swift-iOS拖拽的view

    guard let view = gestureRecognizer.view else { return } switch gestureRecognizer.state { case .began: // 手势开始时,记录初始位置 initialCenter = view.center case .changed: // 手势变化时,...

    Swift5.2 (手势)GestureRecognizer.zip

    Swift5.2中的手势识别(GestureRecognizer)是iOS应用开发中常用的一种交互技术,它允许用户通过简单的触摸或滑动操作来触发特定的功能。在iOS、macOS等Apple平台的开发中,手势识别扮演着至关重要的角色,使得应用...

    限制任何UIView的UIPinchGestureRecognizer缩放_Objective-C_Swift_下载.zip

    UIView *view = gestureRecognizer.view; if (gestureRecognizer.state == UIGestureRecognizerStateBegan || gestureRecognizer.state == UIGestureRecognizerStateChanged) { CGFloat scale = ...

    ios-可移动改变的大小的View.zip

    这个“ios-可移动改变的大小的View.zip”压缩包提供了一个实现这一功能的示例,主要关注的是手势交互。在这个项目中,重点是`MoveLabel`,一个可以移动和调整大小的UILabel子类。 首先,我们来深入理解手势交互...

    IOS自定义view描绘纸牌和手势处理

    在iOS开发中,自定义视图(Custom View)和手势识别(Gesture Recognition)是两个重要的技术领域,尤其在创建交互式、动态的应用时显得尤为重要。本文将深入探讨如何基于Stanford大学iOS 7课程中的第7课内容,实现...

    swift-仿QQ抽屉效果

    guard let translation = gestureRecognizer.translation(in: view) else { return } if gestureRecognizer.state == .began { drawerViewOriginalPosition = drawerView.frame.origin } else if ...

    6个UIView的弹簧效果布局,添加点击实现

    guard let view = gestureRecognizer.view else { return } // 在这里处理点击事件,例如改变视图的颜色或执行其他操作 } ``` 为了使布局更具动态性,我们还可以添加重力行为(`UIGravityBehavior`),使视图在屏幕...

    ios-view边缘效果.zip

    - iOS SDK提供了多种手势识别器(GestureRecognizer),如UIPanGestureRecognizer、UITapGestureRecognizer等,可以监听用户的滑动、点击等操作。在这个Demo中,开发者可能使用了UIPanGestureRecognizer来检测用户...

    iOS手势代码(旋转、缩放、拖拽等)

    view.transform = view.transform.scaledBy(x: gestureRecognizer.scale, y: gestureRecognizer.scale) gestureRecognizer.scale = 1 } } ``` 同样,设置代理并实现相应的同步识别方法。 ### 结论 iOS手势识别...

    ios拖动视图实现

    let translation = gestureRecognizer.translation(in: view) view.center = CGPoint(x: view.center.x + translation.x, y: view.center.y + translation.y) gestureRecognizer.setTranslation(CGPoint.zero, in...

    ios应用源码之从上往下拉出现加载view,动态加载内容 2018127

    7. **手势冲突处理**:有时下拉刷新可能与TableView的其他手势(如滚动)产生冲突,这时需要正确配置和管理手势识别器(GestureRecognizer)以确保它们协同工作。 通过以上技术,我们可以实现iOS应用中从上往下拉...

    iOS实现pdf文件预览,上下翻页、缩放,读取pdf目录

    pdfView.scale(to: gestureRecognizer.scale) } ``` 5. **读取PDF目录**: - `PDFDocument`的`pages`属性是一个`PDFPage`数组,表示PDF的所有页面。PDF的目录通常包含在PDF的元数据中,可以使用`PDFOutlineRoot...

    swift-自定义截图控件

    guard let view = gestureRecognizer.view else { return } switch gestureRecognizer.state { case .began: // 手势开始时记录初始位置 break case .changed: // 更新截图框的位置 let translation = ...

    如何简单的实现UINavigationViewController侧滑返回上一页功能

    guard let translation = gestureRecognizer.translation(in: view) else { return false } return abs(translation.x) &gt; abs(translation.y) && translation.x } ``` 4. 在`handlePanGesture`方法中,我们需要...

    界面抽屉侧滑

    let translation = gestureRecognizer.translation(in: view) drawerView.center.x += translation.x gestureRecognizer.setTranslation(CGPoint.zero, in: view) case .ended, .cancelled: let velocity = ...

    IOS应用源码——Scroll.rar

    8. **添加手势识别**:开发者可以添加手势识别器(GestureRecognizer)到Scroll View,以便实现自定义的用户交互,比如双击放大等。 9. **嵌套Scroll View**:有时我们需要在一个Scroll View内部再嵌套另一个Scroll...

    自定义手势(拖动UIPanGestureRecognizer)

    .center = CGPoint(x: gestureRecognizer.view!.center.x + translation.x, y: gestureRecognizer.view!.center.y + translation.y) gestureRecognizer.setTranslation(.zero, in: view) } } ``` 这段代码中,`...

    具有自定义手势的ViewControllers提供更好的用户体验_Objective-C_Ruby_下载.zip

    3. **重写识别方法**:在自定义手势类中,你需要实现`- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)...

    swift-PanSlip-使用PanGesture来关闭UIViewController和UIView上的视图

    let translation = gestureRecognizer.translation(in: view) if abs(translation.y) &gt; threshold { // threshold是预设的关闭阈值 // 关闭视图的逻辑 } } } ``` 关闭视图的方式取决于你的具体需求。可以简单...

Global site tag (gtag.js) - Google Analytics