有什么方法可以限制用户手势的持续时间吗?例如,用户可以拖动一个精灵,但从cctouch开始,它只能持续3秒。持续时间过后,应用程序将自动触发cctouch结束方法。如何限制触摸持续时间?
1
A
回答
2
我会建议使用块调度计时器。避免在Cocos2D中使用NSTimer,因为它不允许使用内置的暂停/恢复功能。
时间表如下:
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
[[self scheduler] scheduleBlockForKey:@"menu" target:self interval:3.0f repeat:0 delay:0 paused:NO block:^(ccTime dt)
{
// perform end of touch actions here
}];
}
还可以肯定,如果用户做了你想要的任何计时器被调用之前取消预定的块(ccTouchEnded/ccTouchCancelled很可能):
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
[[self scheduler] unscheduleBlockForKey:@"menu" target:self];
}
2
是的,这是一个简单的策略来实现这一目标。您可以在用户开始实现手势时启动计时器,并在计时器命中时停止计时。
-(void) timerDidTick:(NSTimer *)theTimer{
cpMouseRelease(mouse);
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
NSTimer *aTimer = [NSTimer timerWithTimeInterval:3.0 target:self selector:@selector(timerDidTick:) userInfo:nil repeats:NO] ;
[[NSRunLoop mainRunLoop] addTimer:aTimer forMode:NSRunLoopCommonModes];
CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
cpMouseGrab(mouse, touchLocation, false);
...
}
相关问题
- 1. UITableviewCell中的触摸持续时间
- 2. 如何知道cocos2d中的触摸持续时间?
- 3. Unity持续触摸检测
- 4. videoMaximumDuration不会限制持续时间
- 5. LibGDX的触摸持续时间重复相同的东西?
- 6. 检测iOS中的触摸ID扫描持续时间
- 7. 在javascript中获取触摸的持续时间
- 8. 如何限制触摸输入?
- 9. UIView:如何专门限制触摸
- 10. 如何提取只包含持续时间的持续时间?
- 11. 如何检测Activity上的5秒持续触摸事件?
- 12. 对持续触摸采取行动,而不是仅在触及时触发:
- 13. 的iOS手势的问题 - 如何检测其保持触摸一定时间间隔的触摸事件?
- 14. HTTP持续连接限制
- 15. 在JavaScript中限制振荡器的持续时间问题
- 16. Evernote API沙盒速率限制持续时间大于15秒
- 17. Ionic 2 Native Camera - 视频捕获的限制持续时间
- 18. Asp.Net MVC - 全局限制请求持续时间
- 19. 如何在控制中心制作持续时间滑块? Swift
- 20. 如何限制在我的网站完成考试的持续时间
- 21. 触摸开始和触摸结束之间的时间
- 22. “java.lang.OutOfMemoryError:超出GC开销限制”中的过长GC时间的持续时间
- 23. 蟒持续时间
- 24. JSESSIONID持续时间
- 25. Groovy持续时间
- 26. 长时间触摸surfaceView(android)
- 27. 检测长时间触摸
- 28. 会话的控制持续时间PHP
- 29. 持续时间复制实体ID
- 30. 的Android定制敬酒持续时间
尼斯回答,我是新来的科科斯,我不知道有关NSTimers。谢谢 – 2013-04-22 18:21:04