问题
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.
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];
回答1:
You may need to set the value of multipleTouchEnabled property of your view to YES
(the default value of this property is NO
).
来源:https://stackoverflow.com/questions/14789066/uiview-subclass-ignores-second-touch