这是关于使用MKMapKit的iPhone App:
我为可拖动的注释创建了一个自定义MKAnnotationView.我想创建一个自定义动画.我设置了一个自定义图钉图像,注释是可拖动的(这里没有显示,它发生在mapview中),代码如下:
- (void) movePinUpFinished {
[super setDragState:MKAnnotationViewDragStateDragging];
[self setDragState:MKAnnotationViewDragStateDragging];
}
- (void) setDragState:(MKAnnotationViewDragState) myState {
if (myState == MKAnnotationViewDragStateStarting) {
NSLog(@"starting");
CGPoint endPoint = CGPointMake(self.center.x,self.center.y-20);
self.center = endPoint;
[self movePinUpFinished];
}
if (myState == MKAnnotationViewDragStateEnding) {
NSLog(@"ending");
[super setDragState:MKAnnotationViewDragStateEnding];
[self setDragState:MKAnnotationViewDragStateNone];
[super setDragState:MKAnnotationViewDragStateNone];
}
if (myState == MKAnnotationViewDragStateDragging) {
NSLog(@"dragging");
}
if (myState == MKAnnotationViewDragStateCanceling) {
NSLog(@"cancel");
}
if (myState == MKAnnotationViewDragStateNone) {
NSLog(@"none");
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常,注释向上移动一点,可拖动,当我发布注释时,mapview会收到"dragstateending".
但现在我希望动画在一段时间内运行并将dragStateStarting更改为以下内容:
if (myState == MKAnnotationViewDragStateStarting) {
NSLog(@"starting");
CGPoint endPoint = CGPointMake(self.center.x,self.center.y-20); …Run Code Online (Sandbox Code Playgroud) 难道有人曾经成功覆盖的方法setDragState的MKAnnotationView?如果我尝试谷歌用" mkannotationview setDragState"我只获得三次点击!其中一个是我在stackoverflow上的另一篇文章;)
该参考文献说,当子MKAnnotationView类化子类必须关心dragstate时.但它没有说明如何.仅将拖尾状态设置为MKAnnotationViewDragStateDragging或者MKAnnotationViewDragStateCanceling似乎不够.因为如果我这样做,其中一个问题就是mapview没有收到mapView:annotationView:didChangeDragState:fromOldState:委托函数.
我试图通过在超类中设置dragState来覆盖它.但此时会出现其他错误:例如,如果我拖动annotationView并且我的手指在屏幕上运行,应用程序会崩溃,例如"无法移除观察者的keypath dragstate"(但我的子类不是我所知道的任何观察者) .所以似乎还有其他事情需要关注.
在苹果开发者论坛https://devforums.apple.com/message/203107#203107上的这篇文章中,aroonicus,一个来自苹果的人,提到你必须覆盖[MKAnnotationView setDragState:]但遗憾的是他并没有告诉你如何.
有人可以帮忙吗?有人知道如何覆盖setDragState吗?有没有人创建了MKAnnotationView的工作子类来覆盖setDragState?
再见,
本
我有一个MKAnnotationView(draggable属性设置为YES)自定义图像,通过image属性设置.将注释添加到地图时,它具有自定义图像.但拖动注释时图像会返回默认引脚.image每次dragState改变时我都试图覆盖这个属性.这里也没有运气.