开发者

Keeping objects on top of CoreAnimation effects

开发者 https://www.devze.com 2023-02-21 11:13 出处:网络
Is it possible to keep a view on top of a another view while Core Animation is running on it? I am sliding views in and out from the top and bottom. Currently, the view that is sliding out slides ov

Is it possible to keep a view on top of a another view while Core Animation is running on it?

I am sliding views in and out from the top and bottom. Currently, the view that is sliding out slides over the top of every other view that is currently visible, I'd like to know if I can make a view stay on top of the animation effects.

Here is an example of one of the animations I have now:

CATransition *push = [CATransition animation];
push.type = kCATransitionPush;
push.subtype = kCATransitionFromTop;
[self.grid.layer addAnimation:push forKey:kCATransition];

// Changes to the view here

[CATransaction commit];

The view I want to keep visible does not overlap the original position of the view that is sliding out.

This is an ASCII diagram of the layout of the screen:

+------------------------------+ 
|  View I want to keep on top  |
|------------------------------|
|                              |
|------------------------------|
|    View that will slide up开发者_Python百科   |
|     ^   ^   ^   ^   ^  ^     |
|                              |
|                              |
|                              |
|                              |
|                              |
|                              |
+------------------------------+ 


After a bunch of playing around, I've realised that CoreAnimation respects the natural stacking order of UIViews. This means that if a view was added after the one being animated, it will be placed on top and the animation will happen behind it.

To alter the stacking order of the views, I can use the following messages:

- (void)bringSubviewToFront:(UIView *)view;
- (void)sendSubviewToBack:(UIView *)view;

The stacking order functions and behaviours of UIViews are detailed in other questions and answers.

0

精彩评论

暂无评论...
验证码 换一张
取 消