我正在制作一个 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];