Próbuję „uncenter” widoku mapy i usunąć wszystkie adnotacje. Powodem tego jest to, że MapView będą wykorzystywane przez różnych kontrolerów widoku, aby wyświetlać różne adnotacje i lokalizacje. Co się teraz dzieje jest to, że używam „Usuń adnotacji” metody i je usuwa, ale mapa pozostaje skupione na miejscu, a więc kiedy nowe adnotacje przyjść, to nie rusza. Czy istnieje sposób, aby przywrócić ten region, a jeśli tak, to jaką wartość zresetować go. Próbowałem zero, zero, a niektóre obliczona wartość, ale „animacja core” mówi, że są nieważne. jak mogę dostać to, aby pomniejszyć iz powrotem na moich nowych adnotacji?
Oto niektóre kodu
-(void)recenterMap {
NSArray *coordinates = [_mapView valueForKeyPath:@annotations.coordinate];
CLLocationCoordinate2D maxCoord = {-90.0f, -180.0f};
CLLocationCoordinate2D minCoord = {90.0f, 180.0f};
//NSLog(@%@, [coordinates description]);
for (NSValue *value in coordinates) {
CLLocationCoordinate2D coord = {0.0f, 0.0f};
[value getValue: &coord];
if(coord.longitude > maxCoord.longitude) {
maxCoord.longitude = coord.longitude;
}
if(coord.latitude > maxCoord.latitude){
maxCoord.latitude = coord.latitude;
}
if(coord.longitude < minCoord.longitude){
minCoord.longitude = coord.longitude;
}
if(coord.latitude < minCoord.latitude){
minCoord.latitude = coord.latitude;
}
}
MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center.longitude = (minCoord.longitude + maxCoord.longitude) / 2.0;
region.center.latitude = (minCoord.latitude + maxCoord.latitude) / 2.0;
region.span.longitudeDelta = maxCoord.longitude - minCoord.longitude;
region.span.latitudeDelta = maxCoord.latitude - minCoord.latitude;
[_mapView setRegion: region animated: YES];
}
Ów Methos Wyśrodkuj używam
- (MKAnnotationView *)mapView: (MKMapView *)mapView viewForAnnotation: (id <MKAnnotation>)annotation{
MKAnnotationView *view = nil;
if(annotation != mapView.userLocation){
Annotation *schoolAnn = (Annotation*)annotation;
view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@schoolLoc];
if(nil == view){
view = [[[MKPinAnnotationView alloc] initWithAnnotation:schoolAnn reuseIdentifier:@schoolLoc]autorelease];
}
[(MKPinAnnotationView *)view setAnimatesDrop:YES];
[view setCanShowCallout:YES];
}
else {
[self recenterMap];
}
return view;
}
Ten „inny” kawałek czeka aż Blue Marble krople następnie wyśrodkowany mapę. Mam problem z tym jest to, że kiedy wrócę do poprzedniego widoku kontrolera i usunąć wszystkie adnotacje, więc kiedy wrócę w lokalizacji użytkownika (z jakiegoś powodu) nie pop widok. Jak uzyskać ten pop widok?
Z góry dzięki chłopaki













