iOS - MKMapView showAnnotations:animated:with padding? [英] iOS - MKMapView showAnnotations:animated: with padding?

查看:1429
本文介绍了iOS - MKMapView showAnnotations:animated:with padding?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想能够缩放我的MKMapView以适合它的注释。我已经设法使用iOS7的 showAnnotations 方法。但我也想添加一些padding或插图从地图视图边框。这是因为我有一个半透明的视图覆盖在我的地图的顶部,我不想要注释是这个视图后面的地方。我试过这个:

I want to be able to zoom my MKMapView to fit it's annotations. I have managed to do it using iOS7's showAnnotations method. But I would also like to add some padding or inset from the map view border. This is because I have a semi-transperant view that overlays the top part of my map, and I don't want annotations to be places behind this view. I have tried this:

[self.mapView showAnnotations:annotations animated:YES];
[self.mapView setVisibleMapRect:self.mapView.visibleMapRect edgePadding:UIEdgeInsetsMake(100, 20, 10, 10) animated:NO];

但它不工作,因为我本来希望。任何想法如何我可以做不同?

But it's not working as I would have hoped. Any ideas on how I could do it differently?

推荐答案

您正在以正确的方式做。
尝试改变填充,你会看到差别。

You are doing it the right way. Try changing the padding, you'll see the difference.

其他方式,你的代码中必须有其他东西阻止更改视图

Other way, there must be something else in your code preventing from changing the view

编辑:我完全错了。尝试此操作:

I was totally wrong. Try this:

创建实例变量

BOOL _mapNeedsPadding;

并将其初始化为NO;

and initialize it to NO;

然后将您的mapView代理设置为self并添加到您的类头

Then set your mapView delegate to self and add a to your class header

然后将其添加到您的类

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
    if(_mapNeedsPadding){
        _mapNeedsPadding = NO;
        [self.mapView setVisibleMapRect:self.mapView.visibleMapRect edgePadding:UIEdgeInsetsMake(100, 20, 10, 10) animated:YES];
    }
}



最后调用showAnnotations函数: p>

And finally call your showAnnotations function like this:

_mapNeedsPadding = YES;
[self.mapView showAnnotations:annotations animated:YES];

showAnnimation将触发regionDidChangeAnimated函数。
更改visibleMapRect后,您需要将_mapNeedsPadding设置为NO,因为此函数(setVisibleMapRect:self)也将触发regionDidChangeAnimated。

The showAnnimation will trigger the regionDidChangeAnimated function. You need to set _mapNeedsPadding to NO after changing visibleMapRect because this function (setVisibleMapRect:self) will also trigger regionDidChangeAnimated.

希望这有助于!

这篇关于iOS - MKMapView showAnnotations:animated:with padding?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆