我尝试过使用此方法,但出于某种原因,它不会放大当前位置。有什么我做错了吗?
Appdelegate.m
-(void)handleNetworkChange
{
self.reachability = [Reachability reachabilityForInternetConnection];
[self.reachability startNotifier];
NetworkStatus remoteHostStatus = [self.reachability currentReachabilityStatus];
MapViewController *mapViewController = [[MapViewController alloc]init];
if(remoteHostStatus == NotReachable)
{
self.internetReachable = NO;
}
else
{
self.internetReachable = YES;
[mapViewController userLocation];
}
}
MapViewController.m
-(void)userLocation
{
MKCoordinateRegion mapRegion;
mapRegion.center.latitude = self.mapView.userLocation.coordinate.latitude;
mapRegion.center.longitude = self.mapView.userLocation.coordinate.longitude;
mapRegion.span.latitudeDelta = 0.2;
mapRegion.span.longitudeDelta = 0.2;
[self.mapView setRegion:mapRegion animated:YES];
}
答案 0 :(得分:0)
我只想使用NSNotificationCenter。 你设置了一个等待帖子通知的监听器,一旦收到帖子通知,它将触发一个选择器
这是如何做到的(实际上非常简单)
这需要放在您呈现地图的视图控制器中,最好在viewDidLoad
中[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(runThisFunctionWhenReady:)
name:@"TestNotification"
object:nil];
-(void)runThisFunctionWhenReady
{
// Zoom the map and other funky stuff
}
现在,从应用程序中的任何位置(包括代理),您可以通过发布通知来解决此问题 像这样:
[[NSNotificationCenter defaultCenter]
postNotificationName:@"TestNotification"
object:self];