iOS: MasksToBounds not working during Flip Animation

359 Views Asked by At

I am trying to flip a view and show a different view with an animation looking like flipping a card around.

This all worked well. I made one Parent View that nested 2 child views, these child views are the ones which get flipped. My Parent View has Rounded Corners through(layer.cornerRadius = x) and through layer.masksToBounds the child views don't go over the Bounds of the Parent view.

Anyway when I flip the views during this animation the corners are not rounded. I thought this is probably because when the flip happens the child views don't clip over the parent even with square corners, but then I also tried to add a cornerRadius to the Child Views which again did not work in my case because one of the Child Views nests itself child Views which then clip over the bounds again, which I don't understand at all!

I wrote a function to flip the views:

private func flip(firstView: UIView, secondView: UIView) {

     let transitionOptions: UIViewAnimationOptions = [.transitionFlipFromRight, .showHideTransitionViews]
    UIView.transition(with: firstView, duration: 1.0, options: transitionOptions, animations: {
        firstView.isHidden = !firstView.isHidden
    })

    UIView.transition(with: secondView, duration: 1.0, options: transitionOptions, animations: {
        secondView.isHidden = !secondView.isHidden
    })
}

For the rounded corners I just added a user defined runtime attribute in storyboard: layer.cornerRadius Number 13, as well as layer.masksToBounds Boolean true

I would really appreciate some help.

Thanks a lot!

0

There are 0 best solutions below