Intercepting/Hijacking iPhone Touch Events for MKMapView

后端 未结 6 1422
故里飘歌
故里飘歌 2020-12-01 05:56

Is there a bug in the 3.0 SDK that disables real-time zooming and intercepting the zoom-in gesture for the MKMapView? I have some real simple code so I can detect tap event

6条回答
  •  一向
    一向 (楼主)
    2020-12-01 06:37

    To extend up on @chomasek's answer, in order to only process those touches for the map view, I do the following:

    1. Give the map view a tag, like 99
    2. When I get touch, traverse up the view hierarchy of the receiving view, looking for a view with the above tag.

    Here is the code:

    // this is in the view controller containing the map view
    // kICTagForMapView is just a constant
    _mapView.tag = kICTagForMapView;
    

    Then in sendEvent:

    // this does into the UIWindow subclass
    BOOL isMapView = NO;    
    UIView* superView = touch.view.superview;
    while(superView)
    {
        //Debug(@"superView = %@", superView);
        if (superView.tag == kICTagForMapView)
        {
            isMapView = YES;
            break;
        }
        superView = superView.superview;
    }
    
    if (isMapView == NO) return;
    
    // do stuff here
    

提交回复
热议问题