Ios 如何从appdelegate正确调用mapview当前位置放大方法?
我尝试过使用这种方法,但由于某些原因,它无法放大当前位置。我做错什么了吗 Appdelegate.m MapViewController.mIos 如何从appdelegate正确调用mapview当前位置放大方法?,ios,objective-c,mkmapview,mkuserlocation,Ios,Objective C,Mkmapview,Mkuserlocation,我尝试过使用这种方法,但由于某些原因,它无法放大当前位置。我做错什么了吗 Appdelegate.m MapViewController.m 我只想使用NSNotificationCenter。 您设置了一个等待post通知的侦听器,一旦收到post取消通知,它将触发选择器 这里是如何做到这一点其实很简单 这需要在视图控制器中显示地图,最好在viewDidLoad中 [[NSNotificationCenter defaultCenter] addObserver:self se
我只想使用NSNotificationCenter。 您设置了一个等待post通知的侦听器,一旦收到post取消通知,它将触发选择器 这里是如何做到这一点其实很简单 这需要在视图控制器中显示地图,最好在viewDidLoad中
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(runThisFunctionWhenReady:)
name:@"TestNotification"
object:nil];
缩放方法应放置在同一个viewcontroller中-如下所示:
-(void)runThisFunctionWhenReady
{
// Zoom the map and other funky stuff
}
现在,在应用程序代理中的任何地方,您都可以通过发布通知来触发此操作
像这样:
[[NSNotificationCenter defaultCenter]
postNotificationName:@"TestNotification"
object:self];
是否从app delegateYes调用了你的方法userLocation?是的,我可以确认正在调用该方法。你在哪里显示mapViewController,以及为什么每次调用HandlenNetworkChange方法时都创建mapViewController的实例?我仅以这种方式显示实例作为示例,但我显示mapviewcontroller的方式是通过导航控制器,而不是通过appdelegate。首先可以记录mapView用户位置坐标,以查看是否存在正确的坐标,然后尝试将增量从0.2更改为0.005。
-(void)runThisFunctionWhenReady
{
// Zoom the map and other funky stuff
}
[[NSNotificationCenter defaultCenter]
postNotificationName:@"TestNotification"
object:self];