我正在尝试为一些用图片初始化的标记设置动画,如下RMMarker *marker = [[RMMarker alloc] initWithUIImage:lImage anchorPoint:lPoint];
我在我的 map 上得到了一张静态图像,没有问题。
现在,我需要它比其他注释更明显,所以我想让它闪烁。
这是我已经尝试过的:
在注释层上创建缩放动画
[CATransaction begin];
[CATransaction setAnimationDuration:0.70];
[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
CABasicAnimation *bounceAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
bounceAnimation.repeatCount = MAXFLOAT;
bounceAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1, 1.1, 1.0)];
bounceAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.8, 0.8, 1.0)];
bounceAnimation.removedOnCompletion = NO;
bounceAnimation.autoreverses = YES;
[layer addAnimation:bounceAnimation forKey:@"animateScale"];
[CATransaction commit];
这很好,除了我的标注 View 也在闪烁,因为它共享同一层(并且 Mapbox 在跟踪模式期间与动画混淆,导致方向不正确,因为它会随着用户的每次移动而重置)。
在注释层上创建闪烁动画
[CATransaction begin];
[CATransaction setAnimationDuration:0.60];
[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
opacityAnimation.repeatCount = MAXFLOAT;
opacityAnimation.fromValue = [NSNumber numberWithFloat:1.0];
opacityAnimation.toValue = [NSNumber numberWithFloat:0.3];
opacityAnimation.removedOnCompletion = NO;
opacityAnimation.autoreverses = YES;
[layer addAnimation:opacityAnimation forKey:@"animateOpacity"];
[CATransaction commit];
这不太明显,但这次注释方向是正确的。不过,我的标注 View 仍然在图层上闪烁。
我想做的
我需要一种在不影响图层的情况下为标记图像设置动画的方法。
我使用的最好的动画将是我尝试的第一个动画,没有旋转问题。
到目前为止,我无法为 UIImage 设置动画,因为它没有
addAnimation: forKey:
称呼。我从来没有玩过很多动画,所以任何帮助或指导将不胜感激。
最佳答案
CABasicAnimation
让您走在正确的轨道上,因为这是用于 SDK 中的动画用户位置注释的内容。你可以在这里看到这个:
https://github.com/mapbox/mapbox-ios-sdk/blob/509fa7df46ebd654d130ab2f530a8e380bf2bd59/MapView/Map/RMMapView.m#L3593
你能详细说明一下吗?
This is working well, except that my callout view is also blinking as it shares the same layer (and Mapbox messes with the animation during the tracking mode, resulting in an incorrect orientation as it is reseted with every move of the user anyway).
您确实提出了一个很好的观点,即标注是子图层,因此它也会闪烁。尚未考虑此用例 - 您是否可以取消选择注释并隐藏标注?
但是后半部分是什么意思?
关于ios - MapBox(iOS)上的动画标记注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26976244/