见如下代码:
UISwipeGestureRecognizer *swipeleft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeleft)]; swipeleft.direction = UISwipeGestureRecognizerDirectionleft; [[[CCDirector sharedDirector] vIEw] addGestureRecognizer:swipeleft]; UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeRight)]; swipeRight.direction = UISwipeGestureRecognizerDirectionRight; [[[CCDirector sharedDirector] vIEw]addGestureRecognizer:swipeRight]; UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeUp)]; swipeUp.direction = UISwipeGestureRecognizerDirectionUp; [[[CCDirector sharedDirector] vIEw]addGestureRecognizer:swipeUp]; UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeDown)]; swipeDown.direction = UISwipeGestureRecognizerDirectionDown; [[[CCDirector sharedDirector] vIEw]addGestureRecognizer:swipeDown];
以上代码将添加4个监听器(Listeners)监视滑向4个不同方向。
手势识别器需要添加到UIVIEw上。而Cocos2D应用程序的主UIVIEw是OpenGL vIEw,该vIEw用来渲染整个Cocos2D app的显示的内容。
我们可以通过CCDirector实例的vIEw属性来访问该main UIVIEw。
UISwipeGustureRecognizer为每个滑动方向关联一个方法。
iOS的输入处理就是可以这么简单。
总结以上是内存溢出为你收集整理的给Cocos2D视图添加手势支持全部内容,希望文章能够帮你解决给Cocos2D视图添加手势支持所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)