Custom ease in animateWithDuration?

After a bunch of researches, the following code works for me.

  1. Create an explicit core animation transaction, set your desired timing function.
  2. Use eigher or both UIKit and CAAnimation to perform the changes.

    let duration = 2.0
    
    CATransaction.begin()
    CATransaction.setAnimationDuration(duration)
    CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(controlPoints: 0.8, 0.0, 0.2, 1.0))
    CATransaction.setCompletionBlock {
        print("animation finished")
    }
    
    // View animation
    UIView.animate(withDuration: duration) {
        // E.g. view.center = toPosition
    }
    
    // Layer animation
    view.layer.position = toPosition
    view.layer.bounds.size = toSize
    
    CATransaction.commit()
    

With iOS 10.0 you can use UIViewPropertyAnimator.

https://developer.apple.com/documentation/uikit/uiviewpropertyanimator

See https://developer.apple.com/videos/play/wwdc2016/216/


That's because UIViewAnimationCurve is an enumeration - its basically human-readable representations of integer values used to determine what curve to use.

If you want to define your own curve, you need to use CA animations.

You can still do completion blocks and groups of animations. You can group multiple CA Animations into a CAAnimationGroup

let theAnimations = CAAnimationGroup()
theAnimations.animations = [positionAnimation, someOtherAnimation]

For completion, use a CATransaction.

CATransaction.begin()
CATransaction.setCompletionBlock { () -> Void in
    // something?
}
// your animations go here
CATransaction.commit()