UIView翻转过渡令人讨厌的Flash [英] Annoying Flash on UIView Flip Transition

查看:120
本文介绍了UIView翻转过渡令人讨厌的Flash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在视图A-1和背面视图A-2之间使用UIView.transitionFromView:toView:进行翻转过渡。这些视图有许多兄弟,因为我不希望整个超级视图旋转,所以我插入一个临时容器视图,它足够大以将A-1和A-2都包含到视图层次结构中,并插入A-1直接转换之前。

问题在于,视图A-1在转换开始时立即消失,这很丑陋。我认为它可能会消失,当我将它插入到临时容器视图中时(因为将它添加到容器隐式地将其从它的正常超级视图中移除),但尽我所知,这不会发生在这一点上。我使用的代码如下所示:

  [container addSubview:fromView]; 
[self.view addSubview:container];

[UIView transitionFromView:fromView toView:toView duration:2
options:UIViewAnimationOptionTransitionFlipFromRight
...];

我在完成例程中解开并移除容器,我在这里不会显示闪存问题出现在代码执行之前。



我必须在CALayer级别执行此操作以避免此问题吗?我是否误解了如何进行视图到视图的转换?任何想法,将不胜感激,
霍华德

解决方案

明白了!我应该知道,因为我过去曾经被这种事情咬过(并且愚蠢地认为我再也不会犯同样的错误了。:-)这就是关于那个魔术重绘时刻的事情 - 在插入临时容器进入层次结构并将'fromView'移动到容器中,您需要调用

  [self performSelector:@selector(doAnimation: )withObject:transitionInfo afterDelay(0)] 

返回到主runloop,以便更新的层次结构可以在实际执行动画之前重新绘制自己。 'transitionInfo'参数只是一个用于将'fromView'和'toView'参数传递给动画例程的字典。

Howard

I'm trying to do a flip transition between a view, A-1, and a backside view, A-2, using UIView.transitionFromView:toView:. These views have a number of siblings, and since I don't want the entire superview to rotate, I insert a temporary container view that's just large enough to contain both A-1 and A-2 into the view hierarchy and insert A-1 into that immediately prior to the transition.

The problem is that view A-1 disappears with an unsightly flash as soon as the transition starts, which is ugly. I thought it might be disappearing when I insert it into the temporary container view (since adding it to the container implicitly removes it from its normal superview), but as best I can tell, it isn't happening at that point. The code I'm using looks something like this:

[container addSubview:fromView];
[self.view addSubview:container];

[UIView transitionFromView:fromView toView:toView duration:2
                   options:UIViewAnimationOptionTransitionFlipFromRight
                   ... ];

I unhook and remove the container in the completion routine, which I'm not showing here as the flash problem occurs before that code gets executed.

Do I have to do this at the CALayer level to avoid this problem? Am I misunderstanding something about how view-to-view transitions are supposed to work? Any thoughts would be appreciated, Howard

解决方案

Got it! I should have known, as I've been bitten by this in the past (and foolishly thought I'd never make the same mistake again. :-) It's all about that magic "redraw moment" thing -- after inserting the temporary container into the hierarchy and moving the 'fromView' into the container, you need to call

[self performSelector:@selector(doAnimation:) withObject:transitionInfo afterDelay(0)]

to get back to the main runloop so that the updated hierarchy can redraw itself before you actually do the animation. The 'transitionInfo' argument is just a dictionary for passing the 'fromView' and 'toView' arguments to the animation routine.

Howard

这篇关于UIView翻转过渡令人讨厌的Flash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆