Cocos2d iphone 正确的滑动手势识别器iOS

Cocos2d iphone 正确的滑动手势识别器iOS,cocos2d-iphone,box2d,box2d-iphone,Cocos2d Iphone,Box2d,Box2d Iphone,我还没有找到关于如何为iOS正确设置手势识别器的教程。 我需要检测上下滑动,以及它们的回调 任何帮助,谢谢。谢谢。您需要两个识别器,一个用于向上滑动,另一个用于向下滑动: UISwipeGestureRecognizer* swipeUpGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeUpFrom:)]; swipeUpGestureReco

我还没有找到关于如何为iOS正确设置手势识别器的教程。 我需要检测上下滑动,以及它们的回调


任何帮助,谢谢。谢谢。

您需要两个识别器,一个用于向上滑动,另一个用于向下滑动:

UISwipeGestureRecognizer* swipeUpGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeUpFrom:)];
swipeUpGestureRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
对于处理程序:

- (void)handleSwipeUpFrom:(UIGestureRecognizer*)recognizer {

}
最后,将其添加到视图中:

[view addGestureRecognizer:swipeUpGestureRecognizer];

另一个方向也是如此(只需将所有的
向上
s更改为
向下
s)。

这在Xcode 7.3中对我有效,Swift 2.2

import UIKit

class Viewcontroller: UIViewController
{
    override func viewDidLoad()
    {
        super.viewDidLoad()
        createAndAddSwipeGesture()
    }

    private func createAndAddSwipeGesture()
    {
        let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(Viewcontroller.handleSwipeLeft(_:)))
        swipeGesture.direction = UISwipeGestureRecognizerDirection.Left
        view.addGestureRecognizer(swipeGesture)
    }

    @IBAction func handleSwipeLeft(recognizer:UIGestureRecognizer)
    {
        print(" Handle swipe left...")

    }
}

你是对的:我太专注于认为刷卡识别器的要点是有一个方向识别器。。。我添加了那个步骤…我从未设置过视图。。我可以将什么作为默认视图或当前视图?我还要将所有这些都放在init方法中吗?(我希望它应用于整个iPhone屏幕),然后将其添加到:
[UIApplication sharedApplication].delegate.window
;既然你说你没有视图,我想把代码放在appDidFinishLaunching的地方。。。通常的位置是视图控制器内的
viewDidLoad
,不,该视图不工作。我想的更多的是
[[CCDirector sharedDirector]视图]
或self,但这也不起作用。