相关疑难解决方法(0)

iOS CAKeyFrameAnimation Scaling在动画结束时闪烁

在关键帧动画的另一个测试中,我正在组合theImage沿着贝塞尔曲线路径移动UIImageView(被调用)并在移动时缩放它,导致路径末端的图像大2倍.我这样做的初始代码中包含以下元素来启动动画:

UIImageView* theImage = ....
float scaleFactor = 2.0;
....

theImage.center = destination;
theImage.transform = CGAffineTransformMakeScale(1.0,1.0);

CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
[resizeAnimation setToValue:[NSValue valueWithCGSize:CGSizeMake(theImage.image.size.height*scaleFactor, theImage.image.size.width*scaleFactor)]];
resizeAnimation.fillMode = kCAFillModeBackwards;
resizeAnimation.removedOnCompletion = NO;  

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.path = [jdPath path].CGPath;
pathAnimation.fillMode = kCAFillModeBackwards;
pathAnimation.removedOnCompletion = NO;

CAAnimationGroup* group = [CAAnimationGroup animation];
group.animations = [NSArray arrayWithObjects:pathAnimation, resizeAnimation, nil];
group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
group.removedOnCompletion = NO;
group.duration = duration;
group.delegate = self;

[theImage.layer addAnimation:group forKey:@"animateImage"];
Run Code Online (Sandbox Code Playgroud)

然后,当动画完成时我想保留更大尺寸的图像,所以我实现:

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag …
Run Code Online (Sandbox Code Playgroud)

scaling flicker uiimageview cakeyframeanimation ios

6
推荐指数
1
解决办法
8000
查看次数

使用 CAKeyframeAnimation 反转 UIImageView 的旋转

我正在使用以下代码无限旋转图像,旋转是顺时针方向,但我也需要它每旋转 1-2 圈就逆时针旋转,然后再逆时针旋转,如何使其工作?

    /// Image Rotation - CAKeyframeAnimation
func rotate(imageView: UIImageView, rotationSpeed: Double) {

    let animation = CAKeyframeAnimation(keyPath: "transform.rotation.z")

    animation.duration = rotationSpeed
    animation.fillMode = CAMediaTimingFillMode.forwards
    animation.repeatCount = .infinity
    animation.values = [0, Double.pi/2, Double.pi, Double.pi*3/2, Double.pi*2]

    /// Percentage of each key frame
    let moments = [NSNumber(value: 0.0), NSNumber(value: 0.1),
                   NSNumber(value: 0.3), NSNumber(value: 0.8), NSNumber(value: 1.0)]
    animation.keyTimes = moments

    imageView.layer.add(animation, forKey: "rotate")
}
Run Code Online (Sandbox Code Playgroud)

cakeyframeanimation ios swift

5
推荐指数
1
解决办法
135
查看次数

标签 统计

cakeyframeanimation ×2

ios ×2

flicker ×1

scaling ×1

swift ×1

uiimageview ×1