我想动画,实际上褪色,“内” drawRect [英] I want to animate, in fact fade, "within" drawRect

查看:116
本文介绍了我想动画,实际上褪色,“内” drawRect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使drawRect将 从上一个场景移到下一个?



惊人地)您可以在drawRect 中进行动画处理 - 尝试。



但是,它从新鲜开始,从空白开始。 strong>因此,例如,如果你在drawRect中放入一个淡入的动画块,前一个场景消失,新场景将从白色消失。



屏幕将从先前图像 (在上一个drawRect周期中绘制)中的 淡出到我刚刚绘制的新图像...。

有什么办法可以做到这一点,可能是通过操纵drawRect的事情很麻烦。



这似乎是一个非常常见的用例 - 从一个场景到下一个 混合。



p>

当然,显然这可以在核心动画环境或许多其他方式,但drawRect从一个drawRect淡化到下一个是一个明显的想法。



p>只感谢WrightCS,我们现在知道drawRect完美处理动画。只需将此代码粘贴到任何drawRect的末尾,然后尝试:

  self.alpha = 0.0; 
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
self.alpha = 1.0;
[UIView commitAnimations];

它将整个drawRect作为一个巨大的块来处理,无论它如何复杂,动画。是的,它甚至包括画在屏幕外区域,位图渲染或任何其他。一切都得到动画。谁知道?



手头的问题 - 如何让它从上一个场景开始动画而不是从空白开始?

解决方案

您可以对alpha进行动画处理:

  [UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:2.0];
myObject.alpha = 0.0;
[UIView commitAnimations];


Is there a way to make drawRect animate FROM THE PREVIOUS SCENE to the next one?

(Amazingly) you can animate inside drawRect - try it. You can fade, translate or animate any other property.

However, it starts "from fresh", from blank. So for example if you put a fade-in animation block in drawRect, the previous scene with disappear and the new scene will fade up from white.

I want the screen to fade from the previous image (drawn in the previous cycle of drawRect) to the new image I have just drawn ... err, am drawing.

Is there a way to do that, perhaps trickily by manipulating what's going on with drawRect?

This would seem to be a very common use case - blending from one scene to the next.

Does anyone know the secret?

Of course, obviously this can be done in the core animation milieu or in many other ways, but having drawRect fade from one drawRect to the next is an obvious idea. Cheers.

Astounding update thanks to the genius of WrightCS.....

Thanks only to WrightCS, we now know that drawRect handles animations perfectly. Simply paste this code at the end of any drawRect and try it:

self.alpha = 0.0;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
self.alpha = 1.0;
[UIView commitAnimations];

it treats the entire drawRect, no matter how complex, as one enormous block and it wraps it in that animation. Yes, it even includes painted in offscreen areas, bitmap rendering or anything else. Everything gets animated. Who knew?

The problem at hand - how to make it start the animation from the previous scene rather than start from blank?

解决方案

You can animate the alpha:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
myObject.alpha = 0.0;
[UIView commitAnimations];

这篇关于我想动画,实际上褪色,“内” drawRect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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