ios - 使用 CoreAnimation 变形

标签 ios objective-c uibutton core-animation morphing

我正在创建一个导航按钮。当用户按下它时,按钮的图像应该改变,反射(reflect)它的状态(例如菜单打开/关闭)。我决定为此做一个 morphing-liek 动画。可以用CoreAnimation来实现吗?我需要使用什么动画类型?
我附上图片以清楚地说明我想要什么。此外,您可能会在“Pimp My Ride”节目中看到这些动画。
Morphing sample

最佳答案

您可以使用 animationImages UIImageView 的属性,像这样:

myImageView = [[UIImageView alloc] initWithFrame:myImageViewbounds];

//Add images which will be used for the animation using an array. These should exist in your project and bundle already.
myImageView.animationImages =  @[[UIImage imageNamed:@"1.png"], [UIImage imageNamed:@"2.png"],[UIImage imageNamed:@"3.png"], [UIImage imageNamed:@"4.png"],[UIImage imageNamed:@"5.png"]];

//Set the duration of the entire animation
myImageView.animationDuration = 0.5;

//Set the repeat count. If you don't set that value, by default will be a loop (infinite)
myImageView.animationRepeatCount = 1;

//Start the animation
[myImageView startAnimating];

为了确保像过渡一样平滑变形,您可以查看 GPUImage它有很多很棒的模糊滤镜。理想情况下,您应该能够在两个图像动画之间包裹一个模糊动画来实现您想要的效果。

关于ios - 使用 CoreAnimation 变形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25117343/

相关文章:

ios - iOS objective-c 中登录的唯一 ID

objective-c - 无法在 iOS SDK 中自定义 UINavigationBar 的外观 :

ios - UICollectionView 随机不显示单元格

objective-c - 我如何在 Objective C 中表示当前的 JSON 方案?

ios - 如何检查 S3 存储桶中的文件可用性

swift - “UIButton.titleLabel?.text”无法按预期工作/不会覆盖字符串

ios - 使用 swift 3 更改 iOS 中的按钮标题不起作用

swift - 如何在 UITableView 内的 UITabBar 顶部添加 UIButton

ios - 触及范围外

ios - UIViewControllerAnimatedTransitioning : screen keeps getting black under custom view