本文介绍了缩放时禁用平移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我从iOS的Google Maps api切换到了iOS的maps api.我想在缩放时禁用地图的平移/滚动,以使gps中心点的位置保持不变.有什么建议吗?预先感谢.

I switched from google maps api for iOS to here maps api for iOS . I would like to disable panning/scrolling of map while zooming in order to keep gps location of centre point same. Any suggestion? Thanks in advance.

推荐答案

您可以使用NMAMapGestureDelegateNMAMapViewDelegate的组合来完成此用例.

You can accomplish this use case using a combination of NMAMapGestureDelegate and NMAMapViewDelegate.

例如,您可以实现NMAMapGestureDelegate - (void)mapView:(NMAMapView *)mapView didReceivePinch:(float)pinch atLocation:(CGPoint)location;处理程序方法,以添加一些额外的代码来禁用要阻止的手势.捏手势结束后,然后重新启用手势.

For example, you can implement the NMAMapGestureDelegate - (void)mapView:(NMAMapView *)mapView didReceivePinch:(float)pinch atLocation:(CGPoint)location; handler method to add some extra code to disable the gestures you wish to block. And then re-enable the gestures once the pinch gesture has ended.

这种方法可以解决问题,您可能需要对实现进行一些尝试才能使其按您希望的方式工作:

Something like this should do the trick, you may have to play with the implementation a bit to get it working how you would like:

- (void)mapView:(NMAMapView *)mapView didReceivePinch:(float)pinch atLocation:(CGPoint)location
{
    [mapView disableMapGestures:(NMAMapGestureTypePan | NMAMapGestureTypeTwoFingerPan)];

    // execute default pinch behaviour
    [mapView.defaultGestureHandler mapView:mapView didReceivePinch:pinch atLocation:location];
}

...

- (void)mapViewDidEndMovement:(NMAMapView *)mapView
{
    [mapView enableMapGestures:NMAMapGestureTypeAll];
}

您也可以查看NMAMapView - (NSInteger)respondToEvents:(NSInteger)events withBlock:(NMAMapEventBlock)block.使用respondToEvents响应NMAMapEventGestureEnded事件可能对您的用例更好.

You can look at NMAMapView - (NSInteger)respondToEvents:(NSInteger)events withBlock:(NMAMapEventBlock)block as well. It's possible responding to the NMAMapEventGestureEnded event using respondToEvents may work better for your use case.

更多信息:

地图手势

NMAMapGestureDelegate

NMAMapViewDelegate

地图事件块

这篇关于缩放时禁用平移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 11:51