I'm using CATransition to slide subviews of UIView. But the problem is that the CATransition always appears in whole screen. And it looks like a mess because I have another UI elements in window that become overlapped while transitioning. How can I restrict frame of transition by UIView frame? I tried to set clipToBounds of my UIView to YES. Actually it doesn't help.
7
votes
1 Answers
1
votes
I'm not really 100% sure about this, but I think you're wrong about CATransition applying to the whole screen. It applies to the view you add the animation to.
The idea is that you apply the transition to the parent of the view you actually want to transition. So say you have the following structure.
- UIViewController
- view (main view of UIViewController)
- view you're transitioning
- view (main view of UIViewController)
What you need to do is add a "holding" or "container" view between the main UIViewController view and your actual targeted view, such that it looks like this:
- UIViewController
- view (main view of UIViewController)
- "container" view <-- Apply transition here
- view you're transitioning
- "container" view <-- Apply transition here
- view (main view of UIViewController)
Apply your transition to the container view and you'll be able to clip it, if you want. If it still goes out of bounds, then try turning on clipsToBounds on the containing view, or the layer's masksToBounds property