iOS中如何实现双屏联动操作

用户需要做对比图,加载了两个Mapview控件。 需要实时监听两个地图在移动时候的事件让另外一个地图跟着移动。
已邀请:

马克玲

赞同来自:

【解决办法】:
在IOS中可以通过监听漫游和缩放通知,来实现两个地图控件的联动。在一个地图控件缩放时,同步缩放另外一个地图。 两个地图控件的识别可以通过Tag来表示,我在下面的样例中设置mapview的tag为0 ,mapview2的tag为1。

下面是参考代码:
- (void)mapViewDidLoad:(AGSMapView *)mapView  {

// register for pan notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToEnvChange:) name:AGSMapViewDidEndPanningNotification object:nil];

// register for zoom notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToEnvChange:) name:AGSMapViewDidEndZoomingNotification object:nil];

}

// The method that should be called when the notification arises
- (void)respondToEnvChange: (NSNotification*) notification {

AGSMapView *mapView = (AGSMapView *)notification.object;

NSInteger mapName = mapView.tag;

CGRect rect = mapView.bounds;

AGSEnvelope *env = [mapView toMapEnvelope:rect];

if (mapName == 0) {

[self.mapView2 zoomToEnvelope:env animated:YES];
}
else
{
[self.mapView zoomToEnvelope:env animated:YES];
}

}

注意:为了避免两个地图控件的交互调用,需要调整两个MapView控件宽高完全相同。

要回复问题请先登录注册