【问题标题】:Cocos2d and UISCrollview pass through touchesCocos2d 和 UISCrollview 的透传
【发布时间】:2014-03-03 13:29:02
【问题描述】:

我做了一个CCNode,我称之为ScrollNode,基本上它是一个CCNode,它裁剪一个子节点的某个区域,这个子节点根据透明覆盖UIScrollView的滚动位置在它的x和y位置上移动.

我想要一个 Cocos2d 中的 ScrollView,它感觉是 iOS 平台原生的,它做得很好。

但是,这种处理方式会出现问题。不调用可滚动节点上 CCButton 的触摸(因为该区域上有一个透明的 UIScrollView)当它是“点击”手势而不是“平移手势”时,是否可以通过 UIScrollView 的触摸"

我尝试了以下方法:

// Make sure touches are passed trough all views
for(UIGestureRecognizer *recognizer in self.scrollView.gestureRecognizers)
{
    recognizer.cancelsTouchesInView = NO;
}

但这似乎没有任何区别。

亲切的问候,

【问题讨论】:

    标签: uiscrollview cocos2d-iphone uigesturerecognizer


    【解决方案1】:

    我更喜欢解决这个问题的方法是在UIScrollView 实例上设置我自己的UITapGestureRecognizer。然后,处理程序只需将触摸位置传递给处理我场景中的点击的代码。

    点击和平移手势识别器知道如何相互交互,因此它仍然提供原生体验。

    【讨论】:

      【解决方案2】:

      看来我已经解决了。我对 UIScrollView 进行了子类化,并将 touches* 事件传递给它的父级。这似乎对滚动没有影响,但确保它确实触发了 CCButtons 的点击事件。

      #import "ScrollNodeScrollView.h"
      
      @implementation ScrollNodeScrollView
      
      - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
      {
          [self.superview touchesCancelled:touches withEvent:event];
      }
      
      - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
      {
          [self.superview touchesBegan:touches withEvent:event];
      }
      
      - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
      {
          [self.superview touchesMoved:touches withEvent:event];
      }
      
      - (void)touchesEnded:(NSSet *)aTouches withEvent:(UIEvent *)anEvent
      {
          [self.superview touchesEnded:aTouches withEvent:anEvent];
      }
      
      @end
      

      【讨论】:

        猜你喜欢
        • 2011-01-28
        • 1970-01-01
        • 1970-01-01
        • 2012-09-07
        • 1970-01-01
        • 2011-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多