CATransition显示从动画开始之前的转换结束的单个帧 [英] CATransition showing a single frame from the end of the transition before the animation starts

查看:89
本文介绍了CATransition显示从动画开始之前的转换结束的单个帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一些原本取自苹果示例ViewTransitions的代码,将两个视图互换。

I am using some code which was originally taken from the Apple sample ViewTransitions to swap two views with each other.

CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.3f];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[[container layer] addAnimation:animation forKey:@"swap"];

当我在devlice上执行转换时,我有时会得到最后一帧的单帧闪光过渡动画,然后动画播放顺利。这给第二个视图一个非常刺激的效果,在平滑的动画执行之前闪烁,然后再出来。

When my transition executes on the devlice, I sometimes get a single frame flash of the final frame of the transition animation and then the animation plays smoothly. This gives a very jarring effect of the 2nd view which flickers in and then out again before the smooth animation executes.

我的例子和苹果的例子之间的主要区别是,我的视图不是全屏幕,我有一个容器UIView包含两个子视图,我将我的动画应用到容器层而不是根视图层。我不能看到这应该有很大的区别,虽然。

The main difference between my example and the Apple example is that my views are not full screen, I have a container UIView which contains both sub-views and I am applying my animation to the container layer instead the root view layer. I can not see that this should make much difference though.

这个问题不会发生在模拟器和间歇性(大约60-70%的时间)在设备上。

This issue does not happen at all in the simulator and is intermittent (about 60-70% of the time) on the device. Is anyone else seeing this behaviour and if so, how did you work around it?

更新了更多信息:
代码原来是多部分动画的一部分,但我把它移动到一个按钮触发,以隔离问题。

Updated with more information: The code was originally part of a multi part animation but I moved it to be triggered by a button to isolate the problem. The issue occurs in both situations.

动画代表已实现,但已删除,尝试隔离问题。

The animation delegates were implemented but have been removed to try and isolate the problem.

视图在动画期间不会改变,事实上 [container setUserInteractionEnabled:NO] 正在被调用(但是如果没有用户交互被禁用也会出现问题)。

The views are not changing during the animation and in fact [container setUserInteractionEnabled:NO] is being called (but the problem also happens without user interaction being disabled).

我已经尝试从过渡的中间开始动画,结束前使用 setStartProgress setEndProgress ,再次问题仍然存在。

I have tried starting the animation from the middle of the transition and ending before the end using setStartProgress and setEndProgress, again the problem persists.

我试着放慢动画持续时间, >

I have tried slowing the animation duration right down as well with no effect.

推荐答案

解决了,我错过了一个关键的部分,我认为是不相关的;)在上面的代码示例中设置动画后,

Solved, I had missed a key piece of this that I thought was irrelevant ;) After setting up the animation in the code sample above, I was swapping the views out in the same method.

将其移动到animationDidStart代理解决了问题。

Moving it to the animationDidStart delegate fixed the issue.

这篇关于CATransition显示从动画开始之前的转换结束的单个帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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