Ios 获取所有当前UITouch,包括非';t正在更新

Ios 获取所有当前UITouch,包括非';t正在更新,ios,objective-c,touch,uitouch,uievent,Ios,Objective C,Touch,Uitouch,Uievent,所以我在做自定义手势识别,我遇到了麻烦。我需要监视所有当前触摸,但是touchesbeated、touchesend、touchesMoved和touchecancelled都只给我它们监视的触摸。我需要对所有的触摸进行计算,不管它们是否被监控。我做了一些研究,也看到了一些建议,可以自己监控触摸,但这对我来说并不顺利。这是我的密码: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { /* Called wh

所以我在做自定义手势识别,我遇到了麻烦。我需要监视所有当前触摸,但是
touchesbeated
touchesend
touchesMoved
touchecancelled
都只给我它们监视的触摸。我需要对所有的触摸进行计算,不管它们是否被监控。我做了一些研究,也看到了一些建议,可以自己监控触摸,但这对我来说并不顺利。这是我的密码:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */
    [myTouches unionSet:touches];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    NSArray *objects = [myTouches allObjects];

    for (UITouch *touch in touches) {
        for (UITouch *touch2 in objects) {
            if (CGPointEqualToPoint([touch2 locationInView:self.view], [touch previousLocationInView:self.view])) {
                [myTouches removeObject:touch2];
                [myTouches addObject:touch];
            }
        }
    }
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    [myTouches minusSet:touches];
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    [myTouches minusSet:touches];

    NSArray *objects = [myTouches allObjects];

    for (UITouch *touch in touches) {
        for (UITouch *touch2 in objects) {
            if (CGPointEqualToPoint([touch2 locationInView:self.view], [touch previousLocationInView:self.view])) {
                [myTouches removeObject:touch2];
            }
        }
    }
}
我想要的是:
mytoucks
应该是屏幕上所有触摸的精确表示。
我得到的:
mytouchs
不断增长,尽管有时来自事件的触摸会正确注册为与
mytouchs
中的触摸相同。我还做了一个测试,在测试中,我对
touchesbreated
中注册的触摸次数进行了整数计数,然后减去
touchesend
中注册的触摸次数,结果显示该数字始终为正值,这意味着注册的触摸次数多于结束的触摸次数。请帮忙

尝试UIApplication的子类来监视应用程序中的所有触摸

    @interface MyUIApplication : UIApplication
然后在
myui应用程序中使用事件
sendEvent

    - (void)sendEvent:(UIEvent *)event {

        [super sendEvent:event];
        NSSet *allTouches = [event allTouches];
        if ([allTouches count] > 0) {

             //To get phase of a touch
             UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;
             if (phase == UITouchPhaseBegan){

                 //Do the stuff
             }
             //also you can use UITouchPhaseMoved, UITouchPhaseEnded,
             // UITouchPhaseCancelled and UITouchPhaseStationary
        }
    }
别忘了在main中添加类

    int main(int argc, char *argv[])
    {
          @autoreleasepool {
                return UIApplicationMain(argc, argv, NSStringFromClass([MyUIApplication class]), NSStringFromClass([AppDelegate class]));
          }
    }

您也在考虑“touchesCancelled”?我在
touchesCancelled:
中有
[MyTouchs MinssSet:Touchs]
。UIEvent的触摸数组与NSSet
触摸数组不同。我不得不使用这个阵列来进行手动多点触控事件。我不确定它是否完整,但它比
触摸
更完整。使用
[event alltouchs]
获取该数组。谢谢,原来我只需要这么做
AllTouchs
似乎给了我屏幕上所有的触摸,这正是我所需要的。回答一下,我就接受了。
sendEvent:
go在哪里?这是如何与UIViewController交互的?因为MyUIApplication是UIApplication的一个子类,
sendEvent:
将响应所有事件,而与UIViewController无关。