你知不知道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