【问题标题】:iOS: can ccTouchesBegan contain more than one touch?iOS:ccTouchesBegan 可以包含多个触摸吗?
【发布时间】:2013-06-23 16:57:24
【问题描述】:

我想知道 ccTouchesBegan 中的 NSSet 触摸是否可以包含多个触摸。 我做了一些测试,触摸次数始终为 1。

任何人都可以证实这一点?如果只有一次触摸,为什么会有一套?

-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

【问题讨论】:

    标签: ios cocos2d-iphone touch touch-event


    【解决方案1】:

    看看这个

    -(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
         NSSet *set = [event allTouches];
    
         if (set.count == 1) { //first touch
    
         }
         if (set.count == 2) { //second touch
         } //etc.
    

    【讨论】:

      【解决方案2】:

      给你,伙计。

      -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
          UITouch *touch =[[[event allTouches] allObjects] lastObject];
      
          //NSLog(@"touchesBegan ...");
      
          switch ([touch tapCount]) 
          {
              case 1:
                  [self performSelector:@selector(oneTap) withObject:nil afterDelay:.5];
                  break;
      
              case 2:
                  [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(oneTap) object:nil];
                  [self performSelector:@selector(twoTaps) withObject:nil afterDelay:.5];
                  break;
      
              case 3:
                  [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(twoTaps) object:nil];
                  [self performSelector:@selector(threeTaps) withObject:nil afterDelay:.5];
                  break;
      
              default:
                  break;
          }
      
      };
      
      
      
      - (IBAction)oneTap
      {
          NSLog(@"oneTap ...");
      
      
      }
      - (IBAction)twoTaps
      {
          NSLog(@"twoTaps ...");
      
      
      }
      
      - (IBAction)threeTaps
      {
          NSLog(@"threeTaps ...");
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-20
        • 2016-04-05
        • 2014-07-16
        相关资源
        最近更新 更多