UIView subclass ignores second touch

浪尽此生 提交于 2020-01-07 06:47:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!