如何检查MKCoordinateRegion中是否有MKAnnotation可用 [英] How do you check if an MKAnnotation is available within a MKCoordinateRegion

查看:92
本文介绍了如何检查MKCoordinateRegion中是否有MKAnnotation可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到如果我使用MKMapView的 selectAnnotation:animated:,如果MKAnnotation没有显示在我当前的MKCoordinateRegion中,它会将我的地图滚动到屏幕外地图正在显示。

I've noticed that if I use MKMapView's selectAnnotation:animated:, that it will scroll my map off screen if the MKAnnotation is not displayed in the current MKCoordinateRegion that my map is displaying.

是否有一种简单的方法来检查注释当前是否在指定的MKCoordinateRegion屏幕上?我希望能够选择仅在屏幕上而不是屏幕外的注释。

Is there a trivial way to check if an annotation is currently on screen within the specified MKCoordinateRegion? I'd like to be able to select an annotation that's only on screen and not something offscreen.

推荐答案

annotationsInMapRect:方法http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html#//apple_ref/doc/uid/TP40008205\">MKMapView 班级。它返回在给定map rect中可见的所有注释对象的 NSSet 。使用 NSSet containsObject:方法来测试注释是否存在于该组可见注释中。

Use the annotationsInMapRect: method in the MKMapView class. It returns a NSSet of all annotation objects that are visible in the given map rect. Use the containsObject: method of NSSet to test if the annotation is present in that set of visible annotations.

MKMapRect visibleMapRect = aMapView.visibleMapRect;
NSSet *visibleAnnotations = [aMapView annotationsInMapRect:visibleMapRect];
BOOL annotationIsVisible = [visibleAnnotations containsObject:someAnnotation];

此外 visibleMapRect 与地区相同但是只是一种不同的表现形式。取自文档,

Also visibleMapRect is same as the region but just a different form of representation. Take from the docs,


visibleMapRect

地图视图当前显示的区域。

The area currently displayed by the map view.

@property(非原子)MKMapRect visibleMapRect

此属性表示与region属性相同的基本信息,但指定为地图矩形而不是区域。

This property represents the same basic information as the region property but specified as a map rectangle instead of a region.

这篇关于如何检查MKCoordinateRegion中是否有MKAnnotation可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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