我不确定我做错了什么,但我试图抓住一个MKMapView物体.我通过创建以下类来继承它:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapViewWithTouches : MKMapView {
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event;
@end
Run Code Online (Sandbox Code Playgroud)
并实施:
#import "MapViewWithTouches.h"
@implementation MapViewWithTouches
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event {
NSLog(@"hello");
//[super touchesBegan:touches withEvent:event];
}
@end
Run Code Online (Sandbox Code Playgroud)
但看起来当我使用这个类时,我在控制台上看不到任何内容:
MapViewWithTouches *mapView = [[MapViewWithTouches alloc] initWithFrame:self.view.frame];
[self.view insertSubview:mapView atIndex:0];
Run Code Online (Sandbox Code Playgroud)
知道我做错了什么吗?
我需要准确地跟踪centerCoordinate的MKMapView同时用户放大/平移的地图,即,之间的regionWillChangeAnimated:和regionDidChangeAnimated:事件.
我通过尝试锁定MKAnnotation地图的中心来测试以下方法.不幸的是,它们都不能很好地运作:
使用UIPanGestureRecognizer(如描述这里):这个工作得很好,而显示器被触摸,但在地图上是动画的触摸手势完成后不更新.此外,更新滞后于实际centerCoordinate.
使用UIScrollViewDelegateI 子类化MKMapView来接收scrollViewDidScroll:事件.这很有效,但是每次滚动增量都不会触发事件,从而导致生涩的更新.
使用KVO通知:按照这种模式,我试着观察mapview的centerCoordinate.它适用于userLocation,但似乎没有发送通知centerCoordinate.
有关如何centerCoordinate有效准确跟踪的任何想法?
KVO似乎是最好的选择.有没有窍门,以使其与工作MKMapView的centerCoordinate性质?
在MKMapView某些缩放lvl中,所有地图图块都是空白的.我尝试使用最大变焦解决方案.现在我用它像这样:
func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
userSpan = mapView.region.span
if mapView.zoomLevel() > maxZoomLvl
{
mapView.setCenterCoordinate(mapView.centerCoordinate, zoomLevel: maxZoomLvl, animated: true)
}
}
Run Code Online (Sandbox Code Playgroud)
但是当用户缩放到最大值时,它会缩小动画.但是我需要一些解决方案,比如原生苹果地图应用程序:只需阻止最大缩放,无法缩放深度而无需缩放.预期结果:
我正试图在MKMapView上捕捉平移和"滚动结束".使用手势识别器可以轻松进行平移.但是,MKMapView似乎没有在iOS 6中实现UIScrollViewDelegate.这使得解决方案中有没有办法限制MKMapView的最大缩放级别?不行.
思考?理想情况下,我只是利用UIScrollViewDelegate:
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if ([super respondsToSelector:@selector(scrollViewDidEndDecelerating:)]) {
[super scrollViewDidEndDecelerating:scrollView];
}
[self.myDelegate mapDidFinishPanning:self];
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate: (BOOL)decelerate {
if ([super respondsToSelector:@selector(scrollViewDidEndDragging:)]) {
[super scrollViewDidEndDragging:scrollView];
}
if(!decelerate) {
[self.myDelegate mapDidFinishPanning:self];
}
Run Code Online (Sandbox Code Playgroud)
}
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
if ([super respondsToSelector:@selector(scrollViewWillBeginDragging:)]) {
[super scrollViewWillBeginDragging:scrollView];
}
[self.myDelegate mapDidBeginPanning:self];
}
Run Code Online (Sandbox Code Playgroud)
在扩展MKMapView的类中
@interface MyMapView : MKMapView <UIScrollViewDelegate, UIGestureRecognizerDelegate>
Run Code Online (Sandbox Code Playgroud)
但这在iOS 6中不起作用.我在MKMapViewDelegate中看不到任何足够的东西.
我不希望用户缩小更多.有没有办法在Map kit使用swift时设置最大缩放级别?
ios ×4
mkmapview ×4
mapkit ×2
cocoa-touch ×1
ios6 ×1
objective-c ×1
swift ×1
swift3 ×1
tracking ×1
uiscrollview ×1