我正在制作iOS游戏,并且我已经编写了一个UIView子类,它应该能够捕获触摸事件,并且它可以用于单次触摸。但是,如果我已经用一根手指触摸屏幕,然后用另一根手指触摸其他地方,“touchesBegan”就不会被要求进行第二次触摸。
这是类的实现:(Objective-C ++)
#import "BATouchInput.h"
#include "BotsApp.h"
@implementation BATouchInput
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
for (UITouch* touch in touches) {
std::cout << "touch started" << std::endl;
BotsApp::getSingletonPtr()->touchDown(touch);
}
std::cout << "--------------" << std::endl;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
std::cout << [touches count] << std::endl;
for (UITouch* touch in touches) {
BotsApp::getSingletonPtr()->touchMoved(touch);
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
for (UITouch* touch in touches) {
BotsApp::getSingletonPtr()->touchUp(touch);
}
}
@end
我正在通过以下代码创建此类的实例:
BATouchInput * touchRecieverView = [[BATouchInput alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
[[[UIApplication sharedApplication] keyWindow] addSubview: touchRecieverView];