我嘗試在地圖視圖上檢測事件。我只需要檢測縮放(雙擊或2個手指在屏幕上)。我嘗試添加一個檢測事件的UIview圖層,但是如果我添加一個圖層,則會失去對地圖的控制(How to intercept touches events on a MKMapView or UIWebView objects?)檢測地圖上的屏幕上的2個手指MapKit
感謝您的幫助!
Tony
我嘗試在地圖視圖上檢測事件。我只需要檢測縮放(雙擊或2個手指在屏幕上)。我嘗試添加一個檢測事件的UIview圖層,但是如果我添加一個圖層,則會失去對地圖的控制(How to intercept touches events on a MKMapView or UIWebView objects?)檢測地圖上的屏幕上的2個手指MapKit
感謝您的幫助!
Tony
向我們展示一些代碼。您應該能夠將您不感興趣的任何事件傳遞迴父視圖。例如,在您檢測到兩個手指點擊並做任何您想要的操作之後,將相同的事件傳遞迴mapview並將其自動放大。
這裏是你所說的,一旦你與你的事件檢測完成:
[self.nextResponder touchesBegan:touches withEvent:event];
根據此: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
我錯過了什麼?
感謝您的幫助