ios - 对持续触摸采取行动,而不是仅在触摸开始时采取行动 :

标签 ios objective-c cocoa-touch

我正在编写一个游戏,当用户触摸屏幕的左侧或右侧时,“持续水平”会增加。目前只有当用户第一次触摸屏幕时才会增加(我的代码在下面)。只要用户将手指放在屏幕上,我就希望应用增加。我必须做什么?

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
      UITouch *touch = [touches anyObject];
      CGPoint touchPoint = [touch locationInView:self.view];

      if (self.x >= touchPoint.x){
          self.sustain += 1;

      }else if (self.x <= touchPoint.x){
          self.sustain += 1;

      }
}

最佳答案

increased.Currently the sustain level only increase when you first touch the screen, I want the force to be applied for as long as the user holds their finger on the screen

当用户保持手指不动时,您不会收到任何消息;您的下一条消息将是 touchesEnded。因此,您需要启动一个计时器,并在每次计时器触发时根据需要不断增加力,直到您获得touchesEnded

关于ios - 对持续触摸采取行动,而不是仅在触摸开始时采取行动 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40453593/

相关文章:

iOS UIScrollView 问题

iphone - 使用 xcode 4.5 时没有出现 IOS 7 native 键盘?

iphone - 如何在编辑模式下在 UITableView 中添加额外的单元格?

ios - 用变量定义导出位置

ios - 将 SKScene 渲染到 SKTexture?

ios - NSClassFromString 行为不当和缓存类

objective-c - Objective-C 中的非虚拟方法

iOS SpriteKit 与屏幕边缘的碰撞不起作用

iOS 8.3 SDK 在强制属性声明和区分大小写方面发生了变化

ios - 更改未在 Interface Builder 中创建的 UIButton 的文本