你知不知道MKPinAnnotationView有一个方法“animatesDrop”来动画从顶部的一个pin注释到点在地图上的阴影?好的,是否可以用自定义图像做到这一点?是否可以在MKAnnotationView而不是MKPinAnnotationView中调用animatesDrop?
8
A
回答
20
您可以随时在MKMapViewDelegate方法中执行自定义动画。
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
也许类似的东西(你不会得到花哨的影子动画,如果你想它,你需要自己做):
- (void) mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
CGRect visibleRect = [mapView annotationVisibleRect];
for (MKAnnotationView *view in views) {
CGRect endFrame = view.frame;
CGRect startFrame = endFrame; startFrame.origin.y = visibleRect.origin.y - startFrame.size.height;
view.frame = startFrame;
[UIView beginAnimations:@"drop" context:NULL];
[UIView setAnimationDuration:1];
view.frame = endFrame;
[UIView commitAnimations];
}
}
1
感谢@gcamp的回答,它的工作原理不错,但我稍作修改是准确的,其视图将在MapView的被丢弃,请检查下面的代码:只在斯威夫特
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
CGRect visibleRect = [mapView annotationVisibleRect];
for (MKAnnotationView *view in views)
{
CGRect endFrame = view.frame;
endFrame.origin.y -= 15.0f;
endFrame.origin.x += 8.0f;
CGRect startFrame = endFrame;
startFrame.origin.y = visibleRect.origin.y - startFrame.size.height;
view.frame = startFrame;
[UIView beginAnimations:@"drop" context:NULL];
[UIView setAnimationDuration:0.2];
view.frame = endFrame;
[UIView commitAnimations];
}
}
3
相同的答案@gcamp对于那些有兴趣
func mapView(mapView: MKMapView, didAddAnnotationViews views: [MKAnnotationView]) {
let visibleRect = mapView.annotationVisibleRect
for view:MKAnnotationView in views{
let endFrame:CGRect = view.frame
var startFrame:CGRect = endFrame
startFrame.origin.y = visibleRect.origin.y - startFrame.size.height
view.frame = startFrame;
UIView.beginAnimations("drop", context: nil)
UIView.setAnimationDuration(1)
view.frame = endFrame;
UIView.commitAnimations()
}
}
相关问题
- 1. 是否可以在不调用XmlWriter.WriteStartDocument()
- 2. 是否可以在ASP.NET webforms中使用get而不是post?
- 3. 是否可以在GJS中调用Gdk.Seat.grab()?
- 4. 是否可以在Android中调用GC?
- 5. 是否可以在UIview中添加CPTLegend而不是CPTGraphHostingView?
- 6. 是否可以在UIPopoverController中放置按钮而不是视图?
- 7. 是否可以在Android中设置图片而不是文本
- 8. mapView:annotationView:calloutAccessoryControlTapped:给我一个UITouchesEvent而不是MKAnnotationView?
- 9. 如何在常规UIView(而不是地图)上使用MKPinAnnotationView
- 10. 是否可以使用InternetExplorer.Application而不是MSXML2.ServerXMLHTTP来进行http调用
- 11. 是否可以在输入类型中调用预设的颜色调色板而不是标准调色板?
- 12. 是否可以在TD中拥有DIV而不占用列
- 13. 为什么你可以在'initialize'中调用instance_eval(而不是class_eval)?
- 14. 是否可以在MATLAB中使用插值而不调整图像大小?
- 15. 输入是否可以使用咏叹调标签而不是<label>?
- 16. 是否可以链接.all()而不是使用Promise.all()?
- 17. 是否可以用C++而不是C编写OpenCL内核?
- 18. 是否可以使用视图而不是UI线程?
- 19. 是否可以使用Curses打印到STDERR而不是STDOUT?
- 20. 是否可以使用while循环而不是for循环?
- 21. 是否可以使用PreferenceActivity与SQLite而不是res/xml?
- 22. 是否可以创建一个自定义的动画MKAnnotationView?
- 23. 是否可以调用不在MATLAB路径中的函数?
- 24. 是否可以调试Global.asax?
- 25. 是否可以在MQFTE的postdst和presrc调用中调用antscript?
- 26. 在OS X下的Python的raw_input中,是否可以使用readline而不是libedit?
- 27. 是否可以在`flip`中使用一元函数而不是二进制?
- 28. 是否可以提交而不显示在日志中?
- 29. 是否可以在助手文件中调用'remote_function'方法而不是使用Ruby on Rails的控制器?
- 30. OctoberCMS在列表中可用,而不是1和不可用的,而不是0
@gcamp:我也尝试以这种方式,但无法正常工作(图像不改变): MKPinAnnotationView * annView = [MapView的dequeueReusableAnnotationViewWithIdentifier:ident]上; annView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:ident] autorelease]; annView.image = [UIImage imageNamed:@“annotImg.png”]; annView.animatesDrop = TRUE; – Mat 2010-01-26 12:45:37
更改了我的答案! – gcamp 2010-01-26 13:04:57
非常感谢!这对我来说非常有用! – Mat 2010-01-26 19:59:58