Animated scaling to a location / map mark when opening an iOS map

I saw it in other exmaple ios 6 starbucks applications, when my display opens, I want it to show the region as all the British / British islands, then I want it to increase to my specified region of the location the points I have.

Updated code:

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [mapView setMapType:MKMapTypeStandard]; [mapView setZoomEnabled:YES]; [mapView setScrollEnabled:YES]; MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; region.center.latitude = 54.5; region.center.longitude = -3.5; region.span.longitudeDelta = 10.0f; region.span.latitudeDelta = 10.0f; [mapView setRegion:region animated:NO]; [self performSelector:@selector(zoomInToMyLocation) withObject:nil afterDelay:2]; //will zoom in after 1.5 seconds } -(void)zoomInToMyLocation { MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; region.center.latitude = 51.502729 ; region.center.longitude = -0.071948; region.span.longitudeDelta = 0.19f; region.span.latitudeDelta = 0.19f; [mapView setRegion:region animated:YES]; [mapView setDelegate:self]; [self performSelector:@selector(selectAnnotation) withObject:nil afterDelay:0.5]; //will zoom in after 0.5 seconds } -(void)selectAnnotation { DisplayMap *ann = [[DisplayMap alloc] init]; ann.title = @"Design Museum"; ann.subtitle = @"Camberwell, London"; ann.coordinate = region.center; [mapView addAnnotation:ann]; } 

I don’t know if this is correct because the error in this line

 ann.coordinate = region.center; 
+4
source share
2 answers

If you want to start by displaying one region and then zoom in, you will have to issue two or more calls to setRegion , because setRegion alone does not allow you to control the starting area or speed of the animation.

In viewDidLoad set the span start area to see all of the UK (try delta 10.0 instead of 0.15 ). You can also set animated to NO for the start area.

Then, until the end of viewDidLoad schedule the scale to complete in a few seconds:

 - (void)viewDidLoad { ... [self performSelector:@selector(zoomInToMyLocation) withObject:nil afterDelay:5]; //will zoom in after 5 seconds } 

The zoomInToMyLocation method may look like this:

 -(void)zoomInToMyLocation { MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; region.center.latitude = 51.502729 ; region.center.longitude = -0.071948; region.span.longitudeDelta = 0.15f; region.span.latitudeDelta = 0.15f; [mapView setRegion:region animated:YES]; } 


One thing you might have to take care of when using performSelector is to cancel the waiting call if the view is closed or released before the call starts. For example, if the user closes the view two seconds after loading it. After three seconds, the planned method can still be called, but it will work since it has not disappeared. To avoid this, cancel the pending actions in viewWillDisappear: or, when necessary:

 [NSObject cancelPreviousPerformRequestsWithTarget:self]; 
+11
source
 MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; region.center.latitude = Your Latitude ; region.center.longitude = Your Longitude; region.span.longitudeDelta = 0.01f; region.span.latitudeDelta = 0.01f; [map setRegion:region animated:YES]; [map addAnnotation:ann]; 
0
source

All Articles