我将UIWindow子类化,但是由于某种原因,-(void)sendEvent:(UIEvent *)event被调用了2次,以与屏幕进行任何交互。任何想法为什么会发生?

最佳答案

出于调试目的,(应用程序委托的)子类窗口和重写sendEvent:方法

-(void) sendEvent:(UIEvent *)event
{
    NSLog(@"%@",event);
    [super sendEvent:event];
}


您很可能会注意到负责TouchesBegan和TouchesEnded的事件(用于轻击)。可以通过将View子类化并覆盖与触摸相关的方法来进行测试。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"tocuhesBegan");
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesMoved");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesEnded");
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesCancelled");
}


另外,请尝试在视图上拖动/滑动以注意发送到视图的事件计数的变化:)

关于ios - iOS 5.0 sendEvent被调用两次[2],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10578171/

10-12 15:57