【问题标题】:Touches landing in MKMapView are not sent to the UIApplication instance在 MKMapView 中的触摸不会发送到 UIApplication 实例
【发布时间】:2018-11-24 00:15:38
【问题描述】:

我正在我的自定义UIApplication 子类中拦截所有事件(用于调试目的):

[super sendEvent:event];
if(event.type == UIEventTypeTouches){
    if(event.allTouches.anyObject.phase == UITouchPhaseBegan){
    //    NSLog(@"Touch began on view %@", event.allTouches.anyObject.view);
    }
}

它适用于任何触摸,无论视图、手势识别器、用户交互等如何。

但是,我有一个MKMapView,它没有收到任何触摸(启用了用户交互),甚至没有将触摸转发到应用程序实例。换句话说,当我触摸特定的MKMapView 时,应用程序不会调用sendEvent:

这怎么可能?据我所知,无论我做什么,UIApplication 都应该总是sendEvent: 方法上收到触摸。

我错过了什么吗? (我在 iOS 11.4 上)

【问题讨论】:

    标签: touch mkmapview uitouch uiresponder


    【解决方案1】:

    我终于解决了这个问题。

    我不断根据用户的方向(指南针、倾斜等)为地图制作动画,以创建 3D 效果,即使设备倾斜/移动了一点点,这似乎是连续发生的:

    ...
    motionManager = [[CMMotionManager alloc] init];
    motionManager.deviceMotionUpdateInterval = 0.033;
    [motionManager startDeviceMotionUpdatesUsingReferenceFrame:frame
                                                       toQueue:motionQueue
                                                   withHandler:
     ^(CMDeviceMotion* motion, NSError* error){
         //update map
     }];
    ...
    

    在地图更新方法中,我将地图动画化到新的相机数据以在视觉上平滑更新:

    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveLinear
    animations:block completion:nil];
    

    由于持续的动画,视图忽略了触摸输入。

    我已将UIViewAnimationOptionAllowUserInteraction 添加到我的动画选项中,这解决了问题:

    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveLinear 
    | UIViewAnimationOptionAllowUserInteraction animations:block completion:nil];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-31
      • 1970-01-01
      • 2020-12-29
      • 2012-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多