एनोटेशन दृश्य डबल ज़ूम नल पर गायब के साथ इस मुद्दे

वोट
1

मैं iPhone पर MapKit में एनोटेशन दृश्यों के साथ एक समस्या में पड़ गए है। वहाँ कोई समस्या नहीं है - मैं नक्शे पर कस्टम एनोटेशन विचारों आकर्षित करने के लिए लेते हैं। मैं भी खींचकर या ज़ूम करने के बाद उन्हें पुनः बनाने का प्रबंधन। एक उदाहरण ज़ूम लिए दो बार टैप होगा: हालांकि, वहाँ मामलों में जहां redrawing काम नहीं करता है।

मैं कुछ कोड देते हैं, जहां मैं मानचित्र पर विशिष्ट स्थानों पर कुछ आयतों आकर्षित, और जब मैं एक दो उंगली जेस्चर का उपयोग करके ज़ूम, सब कुछ ठीक काम करता है (यानी आयतों दोबारा बनाई हैं)। हालांकि, जब मैं दो बार टैप करें, आयत गायब हो जाते हैं। क्या भी अजनबी है कि सभी तरीकों आदेश है कि वे चाहिए में कहा जाता हो जाता है, और अंत में, यहां तक ​​कि 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

किसी भी मदद की सराहना की है। यहाँ ज़िपित परियोजना है: लिंक

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