【问题标题】:Detect gesture recogniser and send action programatically检测手势识别器并以编程方式发送操作
【发布时间】:2017-03-04 06:17:36
【问题描述】:

我在 UIImageView 上设置/添加了 Tap、Double Tap 和 Pinch 手势,并且在用户交互/触摸时,它工作正常(发送所有动作)。但是在特定的事件中,

我想在我的图像视图上以编程方式发送这些操作(点按、双击和捏合),而不需要用户的触摸/操作。

我的查询是在 imageView 中实现/添加手势。如何在 ImageView 上添加手势?

【问题讨论】:

  • 这是可能的,但您需要将 nil 作为手势识别器的参数传递。查看此以获取更多详细信息stackoverflow.com/questions/17189507/…
  • @NiravD 是的,但这适用于用户交互。我需要获得任何一个(根据要求)添加的手势并在没有用户交互的情况下执行操作。
  • 那是我说检查行 [self handleTap:nil]; 以编程方式调用手势方法,但为此您需要将 nil 作为参数传递,除此之外别无选择
  • @NiravD 好的,我明白了.. 让我实施和检查,什么会更容易

标签: ios objective-c swift3 uiimageview uigesturerecognizer


【解决方案1】:

这是解决办法

for gesture in imageView.gestureRecognizers {
    imageViewAction(gesture: gesture)
}

func imageViewAction(gesture: UIGestureRecognizer){

    if let _gesture = gesture as? UITapGestureRecognizer {
        if _gesture.numberOfTapsRequired == 1 {
            print("Single Tap Gesture...")
        } else if _gesture.numberOfTapsRequired == 2 {
            print("Double Tap Gesture...")
        } else  {
            print("Tap Gesture...")
        }
    } else if let _gesture = gesture as? UIPinchGestureRecognizer {
        print("Pinch Gesture...")
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    相关资源
    最近更新 更多