Problem z dopiskiem Odwiedzin znikają na podwójnym zoomem kranu

głosy
1

Mam uruchomiony na problem z widokami adnotacji w MapKit na iPhone. Udaje mi się narysować widoki niestandardowe adnotacji na mapie - nie ma problemu. I nawet udało się przerysować je po przeciągnięciu lub powiększania. Istnieją jednak przypadki, w których przerysowanie nie działa: Przykładem może być dwukrotnie tap zoom.

Załączam trochę kodu gdzie rysuję kilka prostokątów w określonych miejscach na mapie, a kiedy Powiększenie przy użyciu gest dwoma palcami, wszystko działa w porządku (tj prostokąty są odświeżana). Jednak, kiedy dwukrotnie dotknij, prostokąty znikną. Co jeszcze dziwniejsze jest to, że wszystkie metody nazywa się w kolejności, w jakiej powinny, aw końcu nawet drawRect pobiera nazywane - ale prostokąty nie są rysowane.

Więc tutaj jest kod, spróbuj dla siebie - dwa finger zoom działa, ale dwukrotnie tap zoom nie:

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

Każda pomoc jest mile widziana. Oto projekt spakowany: Link

Utwórz 03/10/2009 o 06:32
źródło użytkownik
W innych językach...                            


1 odpowiedzi

głosy
0

Należy pamiętać, że pochodzenie rama jest w układzie współrzędnych jego rodzica, więc ustawienie go do zera prawdopodobnie wprowadzenie go wyłączyć ekran. Podejrzewam, że przyczyną tego, że nigdy nie działa w ogóle jest to coraz resetu za plecami, w większości przypadków, ale nie w tych, gdzie jest wadliwa.

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

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

Odpowiedział 28/02/2010 o 00:10
źródło użytkownik

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