我在应用程序中使用了pin图像而不是标准引脚,现在我想给自定义引脚提供动画(与标准引脚相同的效果)。如何为自定义图钉图像提供下降动画效果????
答案 0 :(得分: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];
}
}
答案 1 :(得分:6)
如果你不是一次性掉落所有的针脚而是稍微放下它们,那么它的感觉也会变得很凉爽,这样看起来会有针脚效应的雨水。与Apple原生的相似。使用此:
- (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];
}
}
答案 2 :(得分: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;
}];
}
}];
}
}];
}
}
答案 3 :(得分:0)
请注意,当-mapView:didAddAnnotationViews:
等于MKMapView.userTrackingMode
时,MKUserTrackingModeFollowWithHeading
中的注释视图设置动画会产生奇怪的效果。我只是希望Apple为MKAnnotationView
课程提供了投影动画。
答案 4 :(得分:0)
Swift 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
})
}
}