如何检测 MKMapView 是否缩小/缩小?
我正在编写以下代码,
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
mapRegion = mapView.region; //MKCoordinateRegion myRegion in .h
}
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
MKCoordinateRegion newRegion = mapView.region;
if (mapRegion.span.latitudeDelta != newRegion.span.latitudeDelta ||
mapRegion.span.longitudeDelta != newRegion.span.longitudeDelta){
NSLog(@"The zoom has changed");
}
}
我想在用户放大或缩小 MKMapView 时执行一些操作,我应该做什么,但是通过应用上面的代码,如果条件将执行,则使用不会放大/出来但只是会改变地图?
I am writing the following code,
- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
mapRegion = mapView.region; //MKCoordinateRegion myRegion in .h
}
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
MKCoordinateRegion newRegion = mapView.region;
if (mapRegion.span.latitudeDelta != newRegion.span.latitudeDelta ||
mapRegion.span.longitudeDelta != newRegion.span.longitudeDelta){
NSLog(@"The zoom has changed");
}
}
I want to do some operation when user either zoom-in or zoom-out the MKMapView, what should I do but by applying the above code, if condition will execute either use won't zoom-in/out but just will change map?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建
MKMapView+ZoomLevel.h
作为Create
MKMapView+ZoomLevel.m
as在视图控制器中
#import "MKMapView+ZoomLevel.h"
语句,其中MKMapView 被采取。在上述方法中,您可以根据需要获得缩放级别,您唯一要做的就是保持初始缩放并将最新的放大/缩小与该缩放进行比较,然后再次分配给该变量。
如果有任何疑问,请告诉我,我们会解决这个问题:D
编辑
此源代码来自特洛伊的博客。抱歉之前没有提及。
Create
MKMapView+ZoomLevel.h
asCreate
MKMapView+ZoomLevel.m
as#import "MKMapView+ZoomLevel.h"
statement in your view controller where MKMapView is taken.In above methods you can get zoom levels as desired, the only thing you have to do is maintain initial zoom and compare latest zoom in/out with that and assign again to that variable.
In case of any query let me know we will work out on that :D
Edit
This source code is from Troy's Blog. Apologize for not mentioning before.