MKMapView响应touch事件
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px 'Lucida Grande'; color: #929292}TapDetectingWindow.h
////plist> //NBFisheryiPad////Created by shiqyn on 11-6-16.//Copyright 2011 Stongsoft. All rights reserved.//#import <Foundation/Foundation.h>@protocol TapDetectingWindowDelegate<NSObject>- (void)userDidTapObserveView:(id)tapPoint;@end@interface TapDetectingWindow : UIWindow { UIView *viewToObserve; id <TapDetectingWindowDelegate> controllerThatObserves;}@property (nonatomic, retain) UIView* viewToObserve;@property (nonatomic, assign) id <TapDetectingWindowDelegate> controllerThatObserves;@end
TapDetectingWindow.m
////plist> //NBFisheryiPad////Created by shiqyn on 11-6-16.//Copyright 2011 Stongsoft. All rights reserved.//#import "TapDetectingWindow.h"@implementation TapDetectingWindow@synthesize viewToObserve;@synthesize controllerThatObserves;- (id)initWithViewToObserver:(UIView *)view andDelegate:(id)delegate { if(self == ) { self.viewToObserve = view; self.controllerThatObserves = delegate; } return self;}- (void)dealloc { ; ;}- (void)forwardTap:(id)touch { ;}- (void)sendEvent:(UIEvent *)event { ; if (viewToObserve == nil || controllerThatObserves == nil) return; NSSet *touches = ; if (touches.count != 1) return; UITouch *touch = touches.anyObject; if (touch.phase != UITouchPhaseEnded) return; if ( == NO) return; CGPoint tapPoint = ; NSArray *pointArray = , , nil]; if (touch.tapCount == 1) { ;}else if (touch.tapCount > 1){;}}@end
用法:
1.双击MainWindow.xib, 弹出的Window,按control+2,弹出的window attributes窗口中 将class identity设置成TapDetectingwindow.
2.在要使用TapDetectingwindow类中添加如下代码:
TapDetectingWindow* tapDetectWindow = ((TapDetectingWindow *)[.windows objectAtIndex:0]);tapDetectWindow.viewToObserve = mapView;tapDetectWindow.controllerThatObserves = self; 并实现delegate:
#pragma mark TapDetectingWindowDelegate- (void)userDidTapObserveView:(id)tapPoint{DLog(@">>>userDidTapObserveView");;}
页:
[1]