Πρόβλημα με σχολιασμού Προβολές εξαφανίζονται για τη διπλή βρύση ζουμ

ψήφοι
1

Έχω έτρεξε σε ένα πρόβλημα με θέα σχολιασμό στο MapKit για το iPhone. Θα καταφέρει να αντλήσει τις απόψεις έθιμο σχολιασμό στο χάρτη - κανένα πρόβλημα εκεί. Έχω ακόμη καταφέρει να τα αναδιατυπώσει μετά το σύρσιμο ή το ζουμ. Ωστόσο, υπάρχουν περιπτώσεις όπου η επαναχάραξη δεν λειτουργεί: ένα παράδειγμα θα ήταν διπλό άγγιγμα ζουμ.

Επισυνάπτω κάποια κώδικας όπου αντλώ μερικά ορθογώνια σε συγκεκριμένες θέσεις στο χάρτη, και όταν zoom χρησιμοποιώντας μια χειρονομία δύο δακτύλων, όλα λειτουργούν σωστά (δηλαδή τα ορθογώνια είναι επανασχεδιάζεται). Ωστόσο, όταν το διπλάσιο της βρύσης, τα ορθογώνια εξαφανίζονται. Αυτό που είναι ακόμα πιο παράξενο είναι ότι παίρνουν όλες οι μέθοδοι καλούνται με τη σειρά που θα έπρεπε, και στο τέλος, ακόμα και η drawRect παίρνει λέγεται - αλλά τα ορθογώνια δεν έχουν γίνει.

Έτσι, εδώ είναι ο κώδικας, δοκιμάστε για τον εαυτό σας - δύο δάχτυλο ζουμ έργα, αλλά διπλό άγγιγμα ζουμ δεν κάνει:

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

Κάθε βοήθεια είναι ευπρόσδεκτη. Εδώ είναι το φερμουάρ του έργου: link

Δημοσιεύθηκε 03/10/2009 στις 06:32
πηγή χρήστη
Σε άλλες γλώσσες...                            


1 απαντήσεις

ψήφοι
0

Λάβετε υπόψη ότι προέλευσης του πλαισίου είναι στο σύστημα συντεταγμένων της μητρικής της, έτσι ώστε η ρύθμιση είναι στο μηδέν κατά πάσα πιθανότητα την αναβολή της οθόνης. Υποψιάζομαι ότι ο λόγος που λειτουργεί πάντα σε όλα είναι η είναι να πάρει την επαναφορά πίσω από την πλάτη σας, στις περισσότερες περιπτώσεις, αλλά όχι σε εκείνες όπου είναι αποτυχία.

αντικαταστήσει: self.frame = CGRectMake (0,0,40,40)?

με: self.frame = CGRectMake (self.frame.origin.x, self.frame.origin.y, 40,40)?

Απαντήθηκε 28/02/2010 στις 00:10
πηγή χρήστη

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