CATransition how to clip to bounds of UIView?
Asked Answered
B

1

7

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.

Bluebottle answered 9/7, 2010 at 4:44 Comment(0)
A
1

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

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

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

Armil answered 8/3, 2013 at 9:27 Comment(1)
Correct on both accounts: The UIView to which you are applying a transition must be clipped by it's superview, using clipsToBoundsFrauenfeld

© 2022 - 2024 — McMap. All rights reserved.