动画UIImage或UIImageView? [英] Animating a UIImage or UIImageView?

查看:87
本文介绍了动画UIImage或UIImageView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为图像的高度设置动画(从0像素到480像素的高度),以创建自上而下渲染图像的效果。

I'm trying to animate an image's height (from height of 0 pixels to 480 pixels) to create the effect of the image being rendered top-down.

使用UIImageView,我注意到它在Interface Builder中显示正确。但是当它在模拟器中运行时,大小(宽度和高度)总是设置为图像的大小;意思是,如果我将图像视图的高度设置为原始高度的50%,则图像仍然以全高度呈现。

With an UIImageView i noticed that it appears correct in the Interface Builder. But when it runs in the simulator the size (width and height) is always set to whatever the size of the image is; meaning, if I set the height of the image view to be 50% the original height, the image is still rendered in full height.

我也尝试过这样的效果一个UIImage。但是,虽然图像的大小看起来是正确的,但图像会缩放以反映尺寸/宽高比。

I also tried do this effect with an UIImage. However, although the size of the image appears correct, the image is scaled to reflect the size/aspect-ratio.

问题:
我如何实现这一点动态大小调整(即图像大小的动画)而不缩放图像?我想过使用CGImageCreateWithMask,但我很确定会造成巨大的性能打嗝。

Question: How can i achieve this dynamic sizing (i.e. animation of an image's size) while NOT scaling the image? I thought about using CGImageCreateWithMask, but im pretty sure that would create huge performance hiccups.

*更新*

我想要的效果是这样的:
通过使图像高度增长,从下到下(就像在窗口上拉一组百叶窗一样)来为图像设置动画。此图像无法缩放(因为它会失去看起来像盲目的视觉效果)。此图像还必须呈现在另一个图像的顶部。总共有2张图片。

The effect that im looking for is this: Animate an image by making it grow in height, from to-down (like a set of blinds being pulled on a window). This image cannot be scaled (as it would lose the visual effect of looking like a "blind"). This image must also be rendered on top of another image. So there are 2 images total.

*答案*

顶部最近的imageview,我将内容模式设置为Top(因此它不会缩放)。然后在代码中,我将clipsToBounds设置为True。现在我能够为最高的imageview高度设置动画,从而为我提供我正在寻找的效果。

For the top-most imageview, i set the content mode to Top (so it doesnt scale). Then in code, i set the clipsToBounds to True. Now i am able to animate the top-most imageview height thus giving me the effect i am looking for.

推荐答案

如上所述原帖,这里是我似乎偶然发现的答案:

As mentioned in the original post, here is the answer i seem to have stumbled upon:

对于最顶层的imageview,我将内容模式设置为Top(因此它不会缩放) 。然后在代码中,我将clipsToBounds设置为True。现在我能够为最顶层的imageview高度设置动画,从而为我提供我想要的效果。

For the top-most imageview, i set the content mode to Top (so it doesnt scale). Then in code, i set the clipsToBounds to True. Now i am able to animate the top-most imageview height thus giving me the effect i am looking for.

这篇关于动画UIImage或UIImageView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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