2009-09-22 6 views
0

私はマップビュー上でイベントを検出しようとします。私はただズーム(ダブルタップまたは画面上の2つの指)を検出する必要があります。イベントを検出するUIviewレイヤーを追加しようとしましたが、レイヤーを追加するとマップのコントロールが失われます(How to intercept touches events on a MKMapView or UIWebView objects?mapViewで画面上で2本の指を検出する

ありがとうございました!

トニー

答えて

0

私たちにいくつかのコードを見せてください。興味のないイベントは親ビューに渡すことができます。たとえば、2本の指タップを検出して何でもしたい場合は、同じイベントをmapviewに渡して、それをズームします。これにより

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

:Mkmapviewがありlink text

は、イベントのデフォルトの受信機であることをここで

はあなたのイベント検出で行われたら、あなたは呼んでいます。

だから私は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 

私が何かを見逃していましたか?

ありがとうございました

関連する問題