从CAAnimation中的当前位置设置动画

时间:2015-10-20 17:56:16

标签: ios cocoa caanimation

Animation representation

如何从 C 开始,将AB的红球位置设为动画?

即它应首先从C动画到B,然后在AB之间无限制地制作动画。 animation.fromValue = A animation.toValue = B animation.removedOnCompletion = false animation.autoreverses = true animation.repeatCount = Float.infinity animation.duration = 2.0

我有以下代码段

A

此代码段的问题是在开始动画之前将位置重置为C 我希望动画从B开始到A,然后在CMapper.CreateMap<Foo,Bar>() .ForMember(dest => dest.baz, opt => opt.Condition(src => (src.baz >= 0))); 之间制作动画

2 个答案:

答案 0 :(得分:1)

您可能需要使用2种不同的动画:一种是从位置C到位置B,然后是从B返回到A的重复自动反转动画。如果可以使用它,UIView动画比使用它更容易CAAnimations。在深入了解CAAnimation对象之前,我先尝试UIView动画。

答案 1 :(得分:0)

您可以尝试执行以下操作:

        UIView.animateWithDuration(0.2, animations: { () -> Void in
            var frame = self.circleView.frame
            frame.origin = A
            self.circleView.frame = frame
        }) { (finished) -> Void in
            let animation = CABasicAnimation(keyPath: "position")
            animation.fromValue = NSValue(CGPoint: CGPoint(x: A, y: self.circleView.frame.origin.y))
            animation.toValue = NSValue(CGPoint: CGPoint(x: B, y: self.circleView.frame.origin.y))
            animation.removedOnCompletion = false
            animation.repeatCount = Float.infinity
            animation.duration = 2.0
            self.circleView.layer.addAnimation(animation, forKey: "position")

    }

如果你希望它可以反转而不是在到达B时跳到A点,你也可以添加animation.autoreverses = true