我已經在應用程序中使用引腳圖像而不是標準引腳,現在我想給定製引腳賦予動畫(如同標準引腳一樣放置效果)。我怎樣才能提供滴定動畫效果自定義引腳圖像?自定義引腳動畫-MKMapView
9
A
回答
24
實施以下委託方法。
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
MKAnnotationView *aV;
for (aV in views) {
CGRect endFrame = aV.frame;
aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - 230.0, aV.frame.size.width, aV.frame.size.height);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.45];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[aV setFrame:endFrame];
[UIView commitAnimations];
}
}
+5
這個效果很好。應該標出正確答案。 – 2010-08-26 15:32:46
6
,如果你不刪除所有引腳一次下降,但他們每個人有一個小的延遲,使得它看起來像有一種針效果雨也感覺更酷。類似於蘋果本身所做的。使用這個:
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
MKAnnotationView *aV;
float delay = 0.00;
for (aV in views) {
CGRect endFrame = aV.frame;
aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - 430.0, aV.frame.size.width, aV.frame.size.height);
delay = delay + 0.01;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:delay];
[UIView setAnimationDuration:0.45];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[aV setFrame:endFrame];
[UIView commitAnimations];
}
}
+0
是的,這很酷!謝謝 – PrasadW 2015-01-06 06:57:58
0
這對我很好。不記得在那裏我發現它這裏雖然
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
MKAnnotationView *aV;
for (aV in views) {
// Don't pin drop if annotation is user location
if ([aV.annotation isKindOfClass:[MKUserLocation class]]) {
continue;
}
// Check if current annotation is inside visible map rect, else go to next one
MKMapPoint point = MKMapPointForCoordinate(aV.annotation.coordinate);
if (!MKMapRectContainsPoint(self.mapView.visibleMapRect, point)) {
continue;
}
CGRect endFrame = aV.frame;
// Move annotation out of view
aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - self.view.frame.size.height, aV.frame.size.width, aV.frame.size.height);
// Animate drop
[UIView animateWithDuration:0.3 delay:0.03*[views indexOfObject:aV] options:UIViewAnimationCurveLinear animations:^{
aV.frame = endFrame;
// Animate squash
}completion:^(BOOL finished){
if (finished) {
[UIView animateWithDuration:0.05 animations:^{
aV.transform = CGAffineTransformMakeScale(1.0, 0.8);
}completion:^(BOOL finished){
if (finished) {
[UIView animateWithDuration:0.5 animations:^{
aV.transform = CGAffineTransformIdentity;
}];
}
}];
}
}];
}
}
0
注意,在-mapView:didAddAnnotationViews:
動畫註解視圖導致奇怪的效果時MKMapView.userTrackingMode
等於MKUserTrackingModeFollowWithHeading
。我只希望蘋果公司能夠爲MKAnnotationView
課程提供下載動畫。
0
夫特3降動畫
// animate annotation views drop
func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {
for annView in views {
// animate any annotation views except the user pin
if !(annView.annotation?.isKind(of: MKUserLocation.self))! {
let endFrame = annView.frame
annView.frame = endFrame.offsetBy(dx: 0, dy: -500)
UIView.animate(withDuration: 0.5, animations: {
annView.frame = endFrame
})
}
}
相關問題
- 1. MKAnnotations自定義引腳放置動畫
- 2. 拖動引腳時自動滾動mkmapview
- 3. 自定義註釋引腳干擾iphone上的mkmapview的showuserlocation
- 4. 當我放大和縮小MKMapView自定義引腳更改
- 5. mkmapview中註釋引腳的自定義圖像
- 6. MKMapView顯示爲自定義引腳的當前位置
- 7. 地圖上的自定義引腳(註釋)動畫
- 8. 自定義註釋引腳
- 9. DirectShow自定義源引腳
- 10. 引腳移動後MKMapView刷新
- 11. 自定義UICollectionViewCell contentView動畫
- 12. 自定義動畫類
- 13. viewpager的自定義動畫
- 14. NSPopover自定義動畫
- 15. 自定義UINavigationController動畫:CATransition
- 16. iPhone UIButton自定義動畫
- 17. 自定義modalViewController動畫
- 18. 自定義UIScrollView動畫
- 19. 自定義比例動畫
- 20. 自定義動畫在Raphael.js
- 21. PresentViewController與自定義動畫
- 22. insertRowsAtIndexPaths自定義動畫Swift
- 23. 自定義視圖動畫
- 24. 自定義CALayer動畫
- 25. Android - 自定義ViewPager動畫
- 26. 自定義的UINavigationController動畫
- 27. 自定義塞格動畫
- 28. 創建自定義動畫
- 29. Android自定義ProgressDialog動畫
- 30. 動畫自定義演示
[這應該有助於](http://stackoverflow.com/questions/1857160/how-can-i-create-a-custom-pin-drop- animation-using-mkannotationview) – dwery 2010-04-17 14:23:46