相关疑难解决方法(0)

如何拦截触摸MKMapView或UIWebView对象上的事件?

我不确定我做错了什么,但我试图抓住一个MKMapView物体.我通过创建以下类来继承它:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface MapViewWithTouches : MKMapView {

}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event;   

@end
Run Code Online (Sandbox Code Playgroud)

并实施:

#import "MapViewWithTouches.h"
@implementation MapViewWithTouches

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event {

    NSLog(@"hello");
    //[super touchesBegan:touches   withEvent:event];

}
@end
Run Code Online (Sandbox Code Playgroud)

但看起来当我使用这个类时,我在控制台上看不到任何内容:

MapViewWithTouches *mapView = [[MapViewWithTouches alloc] initWithFrame:self.view.frame];
[self.view insertSubview:mapView atIndex:0];
Run Code Online (Sandbox Code Playgroud)

知道我做错了什么吗?

cocoa-touch objective-c iphone-sdk-3.0 mkmapview ios

96
推荐指数
5
解决办法
8万
查看次数

拦截/劫持MKMapView的iPhone Touch事件

3.0 SDK中是否存在禁用实时缩放和拦截MKMapView放大手势的错误?我有一些真正简单的代码,所以我可以检测到tap事件,但有两个问题:

  1. 放大手势始终被解释为缩小
  2. 没有一个缩放手势实时更新Map的视图.

在hitTest中,如果我返回"map"视图,MKMapView功能效果很好,但我没有机会拦截事件.

有任何想法吗?

MyMapView.h:

@interface MyMapView : MKMapView
{
    UIView      *map;
}
Run Code Online (Sandbox Code Playgroud)

MyMapView.m:

- (id)initWithFrame:(CGRect)frame
{
    if (![super initWithFrame:frame])
        return nil;

    self.multipleTouchEnabled = true;

    return self;
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    NSLog(@"Hit Test");
    map = [super hitTest:point withEvent:event];
    return self;
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"%s", __FUNCTION__);
    [map touchesCancelled:touches withEvent:event];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event
{
    NSLog(@"%s", __FUNCTION__);
    [map touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
    NSLog(@"%s, %x", __FUNCTION__, mViewTouched);
    [map touchesMoved:touches withEvent:event]; …
Run Code Online (Sandbox Code Playgroud)

iphone events gesture-recognition

6
推荐指数
3
解决办法
2万
查看次数