以编程方式执行长按手势

时间:2017-05-25 05:19:52

标签: ios objective-c uigesturerecognizer uilongpressgesturerecogni

我正在开发一个sdk。我想以编程方式执行添加到视图中的长按手势。我已经尝试更改手势识别器的状态并将消息调度到主循环但这不执行操作

    for (UIGestureRecognizer *currentGesture in currentElement.gestureRecognizers){
        if ([currentGesture isKindOfClass:[UILongPressGestureRecognizer class]]){
            UILongPressGestureRecognizer *longPressGesture = (UILongPressGestureRecognizer *)currentGesture;
            longPressGesture.state = UIGestureRecognizerStateBegan;
            [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
            longPressGesture.state = UIGestureRecognizerStateChanged;
            [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
            longPressGesture.state = UIGestureRecognizerStateEnded;
            [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
            [longPressGesture reset];
            break;
        }
    }

这就是我尝试过的。任何人都可以帮我解决这个问题吗?

此sdks不适用于转到appstore的应用。

0 个答案:

没有答案