翻转过渡期间子视图不显示
我正在容器视图的两个子视图之间进行翻转过渡。容器视图不是全屏的,也不是视图控制器的根视图(它是其子视图,大约占据屏幕的底部三分之一)。
在翻转过渡中切换的两个子视图(均为 UIImageView)中,其中一个依次有两个子视图(同样是 UIImageView 类型)。该子视图是由于转换而“消失”的子视图。
一旦过渡开始,现有的 UIImageView 实例就会正常翻转,但它的两个子实例立即消失。在后半部分,输入的 UIImageView 实例没有出现任何问题(它没有子级)。
我尝试使包含视图全屏且不透明,但没有效果。我读到了有关 contentMode、contentStretch 和 autoresizing mask 的内容,但似乎并非如此。
我正在使用旧式动画块。我尝试设置块内进入/退出子视图的隐藏属性,并在块内添加/删除它们,但结果是相同的。我什至尝试使用现代语法、Objective-C 代码块,但仍然没有任何变化。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将您的 UIImageViews 及其子级放入两个单独的 UIViews 中。轻拂这些 UIView - 它们的内容不会消失。
Try putting your UIImageViews with their children into two separate UIViews. Flick these UIViews - their content won't go away.
我找到了答案:孩子们是在动画块开始之前添加的(在与动画块相同的方法内,之前几行)。
我之前测试过添加其他子项(例如,在 -viewDidLoad 处),并且这些子项在动画期间保留。
我的猜测是,更改视图层次结构包含超出一行“addSubview:”的一些异步处理,并且新的子视图没有及时成为动画的一部分。动画块本身是异步的,但在提交它时肯定必须修复一定数量的事情(例如,视图层次结构)。
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).
实际的问题是,在执行动画块之前添加子项不会显示,因为您的代码没有时间首先返回到主运行循环,而这正是它们实际显示的位置。如果将它们添加到 viewDidLoad 中,没问题。如果您将它们添加到动画之前,它们的显示基本上会被动画覆盖并且不会被看到。
我遇到了完全相同的问题,然后在 Annoying Flash on 中找到了答案UIView 翻转过渡。
祝你好运!
霍华德
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