UIImageView 使用 NSArray 淡入/淡出
我有一个 NSArray 图像,我想在彼此之间淡入/淡出(很像 Flickr 处理主屏幕的方式)。
我遇到的问题是弄清楚如何将 [UIView beginAnimations];
与 NSArray 结合使用...有什么想法吗?
我的代码如下。
提前致谢!
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"show_robmachado.jpg"],
[UIImage imageNamed:@"show_losness.jpg"],
[UIImage imageNamed:@"show_blanchard.jpg"],
[UIImage imageNamed:@"show_tonino.jpg"],
nil];
homeAnimation.animationImages = myImages;
homeAnimation.animationRepeatCount = 0; // 0 = loops forever
homeAnimation.animationDuration = 7.0;
[homeAnimation startAnimating];
I have an NSArray of images that I want to fade in/out between each other (much like how Flickr handles their home screen).
The problem I'm having is figuring out how to utilize the [UIView beginAnimations];
with the NSArray... any idea?
My code is below.
Thanks in advance!
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"show_robmachado.jpg"],
[UIImage imageNamed:@"show_losness.jpg"],
[UIImage imageNamed:@"show_blanchard.jpg"],
[UIImage imageNamed:@"show_tonino.jpg"],
nil];
homeAnimation.animationImages = myImages;
homeAnimation.animationRepeatCount = 0; // 0 = loops forever
homeAnimation.animationDuration = 7.0;
[homeAnimation startAnimating];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数组方法实际上适用于简单的基于帧的动画,而不是过渡。
相反,我会在同一位置有两个 UIImageView,并设置一个可以通过数组工作的计时器,使用 UIView 动画将一个图像视图设置为 alpha 0 的动画,另一个图像视图的 alpha 为 1 的动画。然后你就可以获得一种您想要的渐变开关。
UIImageView 上的 .image 属性也可能是可动画的,尝试在定时循环中更改基于 UIView 的动画块中图像视图上的 .image 并查看是否出现交叉淡入淡出。
The array method is really for simple frame-based animations, not for transitions.
Instead I would have two UIImageViews at the same position, and set up a timer that would work through the array, using UIView animations to animate one image view fading to an alpha of 0 and the other to an alpha of 1. Then you'd get a kind of fading switch you are going for.
The .image property on a UIImageView might also be animatable, try in a timed loop changing .image on an image view in a UIView based animation block and see if you get a cross-fade.