I have an iOS UIView with UIViewAnimationTransitionFlipFromRight. I need it to flip vertically though. The page curl transition won\'t cut it. I assume this wil
Swift 4.0 Version 100% Working Solution
// view1: represents view which should be hidden and from which we are starting
// view2: represents view which is second view or behind of view1
// isReverse: default if false, but if we need reverse animation we pass true and it
// will Flip from Left
func flipTransition (with view1: UIView, view2: UIView, isReverse: Bool = false) {
var transitionOptions = UIViewAnimationOptions()
transitionOptions = isReverse ? [.transitionFlipFromLeft] : [.transitionFlipFromRight] // options for transition
// animation durations are equal so while first will finish, second will start
// below example could be done also using completion block.
UIView.transition(with: view1, duration: 1.5, options: transitionOptions, animations: {
view1.isHidden = true
})
UIView.transition(with: view2, duration: 1.5, options: transitionOptions, animations: {
view2.isHidden = false
})
}
Call of the function:
anim.flipTransition(with: viewOne, view2: viewTwo)
anim.flipTransition(with: viewTwo, view2: viewOne, isReverse: true)
Best practice will be to create UIView extension and hold this function to that extension so it will be accessible to any UIView child object. This solution also can be written using completionBlock.