gpt4 book ai didi

iPhone - 是否可以创建从中心向外显示图像的动画?

转载 作者:太空狗 更新时间:2023-10-30 03:43:37 25 4
gpt4 key购买 nike

我看过很多教程,介绍如何通过更改图像的 alpha 值(例如 here)在 iPhone 上淡入淡出图像。

没关系,但是我正在尝试实现一些稍微不同的东西;而不是整个图像淡入/淡出,我希望图像是动画的,以便随着时间的推移它从图像的中心显示到边缘(反之亦然)。

所以在动画开始时,我希望图像不显示在屏幕上,然后在动画持续期间从中心开始一点一点地显示图像,直到我们到达终点和整个图像显示在屏幕上。

我找不到任何类似的东西,有人知道这在 iPhone 上是否可行吗?任何可能有用的想法/链接?

最佳答案

它应该很容易实现——创建一个 UIImageView 来保存这个东西,将 contentMode 设置为 UIViewContentModeCenter,然后使用一个 CoreAnimation block 来动画化框架中的变化,从零宽度/高度和居中到你的整个区域想要覆盖。

例如

/* coming into here, imageView is a suitable UIImageView,
frameToFill is a CGRect describing the area the image
view should cover when fully unfurled */

// set up image view: content mode is centre so that the current
// frame doesn't affect image sizing, and we'll be keeping the same
// centre throughout so it won't move. The initial frame is on the
// centre and of zero size. The view contents are clipped to the view's
// bounds so that the changing frame does actually cut off the image
imageView.contentMode = UIViewContentModeCenter;
imageView.frame = CGRectMake(frameToFill.origin.x + frameToFill.size.width*0.5f,
frameToFill.origin.y + frameToFill.size.height*0.5f,
0.0f, 0.0f);
imageView.clipsToBounds = YES;

// set up an animation block, lasting 3 seconds, in which the
// only thing animated is the view's frame, expanding back out
// to the original
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3.0f];
imageView.frame = frameToFill;
[UIView commitAnimations];

您的 View 边缘将是坚硬的矩形。如果你想要更微妙的东西,你可能无法使用 CoreAnimation 实现它;下降到 CoreGraphics 级别可能是当天的顺序。

关于iPhone - 是否可以创建从中心向外显示图像的动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6158838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com