2

I have a weird problem with UIView.transition(from:to:)
My setup looks like the following:

  • UIView (root)
    • UIView (front, isHidden false)
    • UIImageView (back, isHidden true)

This view is inside my view controller
Now, I want to flip the front to the back, using this method:

self.back.isHidden = false
UIView.transition(from: self.front, to: self.back, duration: 1, options: [.transitionFlipFromLeft, .showHideTransitionViews], completion: nil)

I am using isHidden and .showHideTransitionViews, since I do not want the front view to be removed from the view hierarchy.

However, the current result is that the flip animation runs correctly, but the front stays visible.
Now when I debug the View hierarchy via XCode, something strange happens:

  • The views get somewhat reevaluated in this process and suddenly, the back is visible (What I want)
  • The front is no longer in the view hierarchy (NOT what I want)

I can not reproduce this behaviour with any calls to setNeedsDisplay() or layoutSubViews() or layoutIfNeeded() to any of the views, may it be the parent or the children.

I created a new project in XCode and tried it there -> it worked instantly as expected.

Since I did (at least I think so) everything as I did before, I don't know why it is not working as expected in my main project.
Btw, I am not using any constraints on any of these views.

EDIT: Now, I observed something. When I play the animation a second time, the back is suddenly visible from the start of the second animation. It still seems to me, as if something prevents the first animation from displaying the views correctly. They seem to be in the right state, but do not get painted properly

skaldesh
  • 1,325
  • 3
  • 15
  • 37

0 Answers0