【发布时间】:2012-02-20 01:15:10
【问题描述】:
我正在运行动画,但我不想在用户触摸屏幕之前开始动画。我想过使用循环,但这需要很多开销,而且我什至无法让它为此工作。
我知道 touchesEnded 和 touchBegin 方法,但我不确定如何以这种方式使用它们。
提前致谢。
【问题讨论】:
我正在运行动画,但我不想在用户触摸屏幕之前开始动画。我想过使用循环,但这需要很多开销,而且我什至无法让它为此工作。
我知道 touchesEnded 和 touchBegin 方法,但我不确定如何以这种方式使用它们。
提前致谢。
【问题讨论】:
您可以在视图控制器代码中使用 touchesBegan / Ended,当您触摸屏幕 (touchesBegan) 或抬起手指 (touches) 时它会触发
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//start animation
}
OR
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
//startAnimation
}
【讨论】:
GestureRecognizers 是你的朋友:Gesture Recognizers
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap:)];
[viewToTap addGestureRecognizer:tapGesture];
- (void) didTap:(UIGestureRecognizer*) sender {
// start you animation here
}
【讨论】: