swiftanimationcatransform3d

Swift animation duration even if I don't want (automatically?)


In my app I need some animation but if it already animated it doens't need to have a duration. But my problem is that it automatically adds a duration.

Here you can see 2 functions, second one is without duration but it really has a duration (from maybe 1 second) , the first function has a duration (and it should have and that's okay) but it isn't 0.6 seconds because if I set it on 30 it still animates very fast.

What am I doing wrong, thanks in advance!

func openMessage() {
    UIView.animate(withDuration: 0.6, delay: 0.0, options: [], animations: {
        var t = CATransform3DIdentity;
        t = CATransform3DMakeRotation(CGFloat(3 * Float.pi / 4), 0, 0, 1)
        self.moveableLineLayer.transform = t;
    }, completion:{(finished:Bool) in })
}

func openMessageWithoutAnimation() {
    self.moveableLineLayer.transform = CATransform3DIdentity
    var t = CATransform3DIdentity;
    t = CATransform3DMakeRotation(CGFloat(3 * Float.pi / 4), 0, 0, 1)
    self.moveableLineLayer.transform = t;
}

Solution

  • Consider using the velocity parameter. From the documentation:

    velocity

    The initial spring velocity. For smooth start to the animation, match this value to the view’s velocity as it was prior to attachment. A value of 1 corresponds to the total animation distance traversed in one second. For example, if the total animation distance is 200 points and you want the start of the animation to match a view velocity of 100 pt/s, use a value of 0.5.