本文介绍了为 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.

* 答案 *

对于最顶部的图像视图,我将内容模式设置为顶部(因此它不会缩放).然后在代码中,我将 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:

对于最顶部的图像视图,我将内容模式设置为顶部(因此它不会缩放).然后在代码中,我将 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 设置动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 11:46