UIView子类忽略了第二次触摸

时间:2013-02-09 14:21:30

标签: multi-touch objective-c++

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

1 个答案:

答案 0 :(得分:0)

您可能需要将视图的multipleTouchEnabled属性值设置为YES(此属性的默认值为NO)。