SORU
26 HAZİRAN 2009, Cuma


Nasıl dokunur bir MKMapView veya UİWebView nesneleri olayları durdurmak için?

Neyi yanlış yapıyorum emin değilim ama MKMapView bir nesne dokunur yakalamaya çalışıyorum. Aşağıdaki sınıf oluşturarak ben alt :

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

@interface MapViewWithTouches : MKMapView {

}

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

@end

Ve uygulama :

#import "MapViewWithTouches.h"
@implementation MapViewWithTouches

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

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

}
@end

Ama bu sınıfı kullanıyorum, Konsol üzerinde hiçbir şey görmek gibi görünüyor

MapViewWithTouches *mapView = [[MapViewWithTouches alloc] initWithFrame:self.view.frame];
[self.view insertSubview:mapView atIndex:0];

Neyi yanlış yaptığımı bir fikriniz var mı?

CEVAP
31 EKİM 2010, Pazar


Önceki yukarıdaki çözümlerden hiçbiri mükemmel, özellikle durumlarda çoklu dokunma içeren çalışır. Bu çözümler en az müdahaleci, ve benim deneyim iyi.

Bunu başarmak için bulduğum en iyi yolu, hareket Algılayıcı. Başka yolları da eksik Apple'ın kodu çoğaltan hackish programlama bir sürü gerektirir.

Burada yaptığım şey bu: engellenebilecek ve diğer jest tanıyıcıları engelleyen bir jest tanıyıcı Uygular. Harita görünümü eklemek ve gestureRecognizer. touchesBegan kullanın, vb touchesMoved. fantezi için.

Nasıl herhangi bir dokunun (sans hileler) bir MKMapView içinde tespit etmek

WildcardGestureRecognizer * tapInterceptor = [[WildcardGestureRecognizer alloc] init];
tapInterceptor.touchesBeganCallback = ^(NSSet * touches, UIEvent * event) {
        self.lockedOnUserLocation = NO;
};
[mapView addGestureRecognizer:tapInterceptor];

WildcardGestureRecognizer.h

//
//  WildcardGestureRecognizer.h
//  Copyright 2010 Floatopian LLC. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef void (^TouchesEventBlock)(NSSet * touches, UIEvent * event);

@interface WildcardGestureRecognizer : UIGestureRecognizer {
    TouchesEventBlock touchesBeganCallback;
}
@property(copy) TouchesEventBlock touchesBeganCallback;


@end

WildcardGestureRecognizer.m

//
//  WildcardGestureRecognizer.m
//  Created by Raymond Daly on 10/31/10.
//  Copyright 2010 Floatopian LLC. All rights reserved.
//

#import "WildcardGestureRecognizer.h"


@implementation WildcardGestureRecognizer
@synthesize touchesBeganCallback;

-(id) init{
    if (self = [super init])
    {
        self.cancelsTouchesInView = NO;
    }
    return self;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (touchesBeganCallback)
        touchesBeganCallback(touches, event);
}

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

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

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

- (void)reset
{
}

- (void)ignoreTouch:(UITouch *)touch forEvent:(UIEvent *)event
{
}

- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer
{
    return NO;
}

- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer
{
    return NO;
}

@end

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • TantalizingTrance

    TantalizingT

    15 ŞUBAT 2009
  • Trevor Eckhart

    Trevor Eckha

    19 Aralık 2009
  • Yo Mama

    Yo Mama

    18 EYLÜL 2005