Subviews not displaying during Flip Transition

僤鯓⒐⒋嵵緔 提交于 2020-01-17 10:42:50

问题


I am doing a flip transition between two subviews of a container view. The container view is NOT fullscreen and is not the root view of the view controller (it is a subview thereof, taking roughly the bottom third of the screen).

Of the two child views being switched in the flip transition (both of them UIImageView), one of them has two children in turn (again, of UIImageView type). This subview is the one that "goes away" as a result of the transition.

As soon as the transition starts, the exiting UIImageView instance flips allright, but its two children disappear immediately. During the second half, the entering UIImageView instance appears with no problems (it has no children).

I have tried making the containing view fullscreen and opaque, to no effect. I read about contentMode, contentStretch and autoresizing masks but doesn't seem to be it.

I am using an old-style animation block. I tried setting the hidden property of the entering/exiting subviews inside the block, and adding/removing them inside the block, but the result is the same. I even tried using modern-syntax, Objective-C code blocks but still no change.


回答1:


Try putting your UIImageViews with their children into two separate UIViews. Flick these UIViews - their content won't go away.




回答2:


I found the answer: the children were being added just before the animation block begins (inside the same method as the animation block, few lines before ).

I tested adding other children earlier on (say, at -viewDidLoad) and those stay during the animation.

My guess is, changing the view hierarchy encompasses some asynchronous precessing beyond the one-line "addSubview:", and the new children didn't make it in time to be part of the animation. The animation block itself is asynchronous but a certain amount of things must certainly be fixed by the time you commit it (e.g., the view hierarchy structure).




回答3:


The actual problem is that the addition of the children immediately prior to executing your animation block isn't shown because your code hasn't had time to return to the main runloop first, which is where they would actually be displayed. If you add them in viewDidLoad, no problem. If you add them immediately prior to an animation though, their display is essentially overridden by the animation and isn't seen.

I had exactly the same problem and then figured out the answer in Annoying Flash on UIView Flip Transition.

Good luck! Howard



来源:https://stackoverflow.com/questions/5321346/subviews-not-displaying-during-flip-transition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!