gpt4 book ai didi

ios - 停止 MKMapView 的惯性滚动

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:42:02 25 4
gpt4 key购买 nike

问题是:我的 MKMapView 带有 scrollEnabled=YESzoomEnabled=YES,我有一个按钮可以设置一些特定的区域到 map 并设置 scrollEnabled=NOzoomEnabled=NO

当我点击那个按钮时,一切正常。但是,如果我稍微滚动我的 map 使其开始进一步滚动,因为惯性并在 map 继续滚动时点击我的按钮,我就会卡在我的 map 在惯性滚动期间滚动到的区域。

如果有帮助,这里有一些代码:

- (void)openMap
{
MKMapView * mapView = self.contentView.locationView.mapView;
mapView.scrollEnabled = YES;
mapView.zoomEnabled = YES;
}

- (void)closeMap
{
MKMapView * mapView = self.contentView.locationView.mapView;
mapView.scrollEnabled = NO;
mapView.zoomEnabled = NO;
CLLocationCoordinate2D coord = {self.event.eventLocation.latitude.floatValue, self.event.eventLocation.longitude.floatValue};
mapView.region = MKCoordinateRegionMakeWithDistance(coord, 500, 500);
}

所以我想要的是当我按下我的按钮时能够立即停止 MKMapView 的惯性滚动。

最佳答案

这似乎是 MKMapView 实现中的错误。我唯一的解决方案是在 closeMap 方法中重新创建 map 。

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

[self addMap];
}

- (void)addMap {

self.map = [[MKMapView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.view addSubview:self.map];
[self.view sendSubviewToBack:self.map];
}


- (void)recreateMap {

[self.map removeFromSuperview];
self.map = nil;
[self addMap];
}


- (void)openMap
{
MKMapView * mapView = self.map;
mapView.scrollEnabled = YES;
mapView.zoomEnabled = YES;
}


- (void)closeMap {

[self recreateMap];
MKMapView * mapView = self.map;
mapView.scrollEnabled = NO;
mapView.zoomEnabled = NO;
CLLocationCoordinate2D coord = {self.event.eventLocation.latitude.floatValue, self.event.eventLocation.longitude.floatValue};
mapView.region = MKCoordinateRegionMakeWithDistance(coord, 500, 500);
}

关于ios - 停止 MKMapView 的惯性滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17420639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com