【问题标题】:How to wait for touch input on iOS如何在 iOS 上等待触摸输入
【发布时间】:2012-02-20 01:15:10
【问题描述】:

我正在运行动画,但我不想在用户触摸屏幕之前开始动画。我想过使用循环,但这需要很多开销,而且我什至无法让它为此工作。

我知道 touchesEnded 和 touchBegin 方法,但我不确定如何以这种方式使用它们。

提前致谢。

【问题讨论】:

    标签: iphone ios touches


    【解决方案1】:

    您可以在视图控制器代码中使用 touchesBegan / Ended,当您触摸屏幕 (touchesBegan) 或抬起手指 (touches) 时它会触发

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    //start animation
    }
    OR
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    //startAnimation
    }
    

    【讨论】:

    • 哦,我没想到在 touchesEnded 方法中调用该方法。谢谢。
    【解决方案2】:

    GestureRecognizers 是你的朋友:Gesture Recognizers

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap:)];
    [viewToTap addGestureRecognizer:tapGesture];
    
    - (void) didTap:(UIGestureRecognizer*) sender {
        // start you animation here
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多