Problema con annotazione Visualizzazioni scomparsa sul doppio tap zoom

voti
1

Ho incontrato un problema con viste di annotazione nel MapKit su iPhone. Riesco a disegnare viste di annotazione personalizzati sulla mappa della città - nessun problema. Ho anche riuscito a ridisegnare loro dopo trascinamento o lo zoom. Tuttavia, ci sono casi in cui il ridisegno non funziona: Un esempio potrebbe essere doppio-tap zoom.

Allego qualche codice in cui traggo alcuni rettangoli in punti specifici sulla mappa, e quando lo zoom con un gesto a due dita, tutto funziona bene (vale a dire i rettangoli sono ridisegnato). Tuttavia, quando ho Double Tap, i rettangoli scompaiono. La cosa ancora più strana è che tutti i metodi vengono chiamati nell'ordine in cui si deve, e alla fine, anche il drawRect viene chiamato - ma i rettangoli non sono disegnati.

Quindi, ecco il codice, si prega di provare per lei - due dita zoom opere, ma toccare due volte lo zoom non lo fa:

PlaygroundViewController.h

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

@interface PlaygroundViewController : UIViewController <MKMapViewDelegate>{
 MKMapView *mapView_;
 NSMutableDictionary* myViews_;
}

@end

PlaygroundViewController.m

#import PlaygroundViewController.h
#import Territory.h
#import TerritoryView.h

@implementation PlaygroundViewController

- (void)viewDidLoad {
    [super viewDidLoad];
 mapView_=[[MKMapView alloc] initWithFrame:self.view.bounds];
 [self.view insertSubview:mapView_ atIndex:0];
 mapView_.delegate = self;
 [mapView_ setMapType:MKMapTypeStandard];
    [mapView_ setZoomEnabled:YES];
    [mapView_ setScrollEnabled:YES];
 myViews_ = [[NSMutableDictionary alloc] init];
 for (int i = 0; i < 10; i++ ) {
  Territory *territory;
  territory = [[[Territory alloc] init] autorelease];
     territory.latitude_ = 40 + i;
  territory.longitude_ = -122 + i;
  [mapView_ addAnnotation:territory];

 }
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
 MKAnnotationView* territoryView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@Territory];
 if (!territoryView){
  territoryView = [[[TerritoryView alloc] initWithAnnotation:annotation reuseIdentifier:@Territory] autorelease];
  Territory* currentTerritory = (Territory*) annotation;
  [myViews_ setObject:territoryView forKey:currentTerritory.territoryID_];
 }  
    else{
  territoryView.annotation = annotation;
 }  
 return territoryView; 
}

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
 for (NSObject* key in [myViews_ allKeys]) {
  TerritoryView* territoryView = [myViews_ objectForKey:key];
  [territoryView initRedraw];
 }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)dealloc {
    [super dealloc];
}

Territory.h

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


@interface Territory : NSObject <MKAnnotation> {
 float latitude_;
 float longitude_;
 NSString* territoryID_;
}

@property (nonatomic) float latitude_;
@property (nonatomic) float longitude_;
@property (nonatomic, retain) NSString* territoryID_;


@end

Territory.m

#import Territory.h

@implementation Territory

@synthesize latitude_;
@synthesize longitude_;
@synthesize territoryID_;


- (CLLocationCoordinate2D)coordinate {
 CLLocationCoordinate2D coord_ = {self.latitude_, self.longitude_};
 return coord_;
}

-(id) init {
 if (self = [super init]) {
  self.territoryID_ = [NSString stringWithFormat:@%p, self];
 }
 return self;
}


@end

TerritoryView.h

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

@interface TerritoryView : MKAnnotationView {

}

- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier;
- (void)initRedraw;

@end

TerritoryView.m

#import TerritoryView.h

@implementation TerritoryView

- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithAnnotation:annotation reuseIdentifier:@Territory]) {
  self.initRedraw;
    }
    return self;
}

- (void)initRedraw {
 self.frame = CGRectMake(0,0,40,40);
 [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
 NSLog(@in draw rect);
}

@end

Ogni aiuto è apprezzato. Ecco il progetto zip: Link

È pubblicato 03/10/2009 alle 06:32
fonte dall'utente
In altre lingue...                            


1 risposte

voti
0

Tenete a mente che l'origine del telaio è nel sistema di coordinate del suo genitore, quindi impostandolo a zero è probabilmente metterlo fuori dallo schermo. Ho il sospetto che il motivo per cui sempre funziona a tutti è il ripristino è sempre dietro la schiena nella maggior parte delle situazioni, ma non in quelli dove è mancato.

sostituire: self.frame = CGRectMake (0,0,40,40);

con: self.frame = CGRectMake (self.frame.origin.x, self.frame.origin.y, 40,40);

Risposto il 28/02/2010 a 00:10
fonte dall'utente

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more