UIView子类忽略第二触 [英] UIView subclass ignores second touch
问题描述
我正在制作一个iOS游戏,并且编写了一个UIView子类,该子类应该捕获触摸事件,并且可以按单次触摸的方式工作.但是,如果我已经用一根手指触摸了屏幕,然后在另一处用另一根手指触摸了屏幕,则第二次触摸不会调用"touchesBegan".
I'm making an iOS game, and I've written a UIView subclass that's supposed to catch touch events, and it works as intended for a single touch. However, if I'm already touching the screen with one finger then touch it with a second finger elsewhere, "touchesBegan" doesn't get called for the second touch.
这是该类的实现:(Objective-C ++)
Here's the implementation of the class: (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
我正在通过以下代码创建此类的实例:
I'm creating an instance of this class through this code:
BATouchInput * touchRecieverView = [[BATouchInput alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
[[[UIApplication sharedApplication] keyWindow] addSubview: touchRecieverView];
推荐答案
You may need to set the value of multipleTouchEnabled
property of your view to YES
(the default value of this property is NO
).
这篇关于UIView子类忽略第二触的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!