我尝试在mapview上检测事件。我只需要检测缩放(双击或两个手指在屏幕上)。我尝试添加一个检测事件的UIview图层,但是如果我添加一个图层,我会失去地图上的控件(How to intercept touches events on a MKMapView or UIWebView objects?)
感谢您的帮助!
贝
答案 0 :(得分:0)
向我们展示一些代码。您应该能够将您不感兴趣的任何事件传递回父视图。例如,在您检测到两个手指点击并执行任何操作后,将同一事件传递回mapview并让其自行缩放。
完成事件检测后,您就会调用以下内容:
[self.nextResponder touchesBegan:touches withEvent:event];
答案 1 :(得分:0)
据此: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
我错过了什么吗?
感谢您的帮助