【问题标题】:Detect 2 fingers on screen on mapView MapKit在 mapView MapKit 上检测屏幕上的 2 个手指
【发布时间】:2011-01-12 23:09:49
【问题描述】:

我尝试在地图视图上检测事件。我只需要检测缩放(在屏幕上双击或两根手指)。我尝试添加一个检测事件的 UIview 层,但是如果我添加一个层,我会失去对地图的控制 (How to intercept touches events on a MKMapView or UIWebView objects?)

感谢您的帮助!

托尼

【问题讨论】:

    标签: iphone events mapkit zooming


    【解决方案1】:

    给我们看一些代码。您应该能够将您不感兴趣的任何事件传递回父视图。例如,在您检测到两根手指点击并执行任何操作后,将相同的事件传递回 mapview 并让它自行缩放。

    完成事件检测后,您可以调用以下代码:

    [self.nextResponder touchesBegan:touches withEvent:event];
    

    【讨论】:

      【解决方案2】:

      据此:link text

      Mkmapview 必须是事件的默认接收者。

      所以我将主窗口的类更改为 MyMainWindow:

      MyMainWindow.h

      #import <Foundation/Foundation.h>
      @class TouchListener;
      
      @interface MyMainWindow : UIWindow {    
      
      TouchListener *Touch;
      
      }
      
      @end 
      

      MyMainWindow.m

       #import "MyMainWindow.h"
      
       @implementation MyMainWindow
      
       - (void)sendEvent:(UIEvent*)event {  
       [super sendEvent:event];  
       [Touch sendEvent:event];
       }
       @end
      

      TouchListener.h

      #import <Foundation/Foundation.h>
      @interface TouchListener : UIView {
      
      }
      
      - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
      - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
      - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
      - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
      - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
      
      @end
      

      TouchListeners.m

      #import "TouchListener.h"
      
      @implementation TouchListener
      
      - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
       return self;
      }
      
      - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
      {
       NSLog(@"Moved");
      }
      
      - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
          NSLog(@"Touch Began");
      }
      
      - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
          NSLog(@"Touch Ended");
      }
      
      - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
          NSLog(@"Touch Cancel");
      }
      
      @end
      

      我错过了什么吗?

      感谢您的帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多