UIImage 视图从一张图像到下一张图像的动画
我想像 UIModalTransitionStyleCrossDissolve 那样平滑地对 UIImageView 中的图像进行动画处理,在一秒钟内变成下一张图像。
目前,我有一个名为“imageView”的 UIImageView * 和一个名为“imageForState”的函数,它返回正确图像的 UIImage * 。
所以我想做的是将图像 A 平滑地动画化为图像 B(如果有的话)。
目前,我的功能是这样的:
- (UIImage *) imageForState{
NSLog(@"state: %d", [save state]);
switch ([save state]) {
case 0:
case 1:
return [UIImage imageNamed:@"Sakuya_Debug.PNG"];
case 2:
return [UIImage imageNamed:@"Sakuya_2_Debug.PNG"];
default:
return NULL;
//Never called
}
}
-(void) tap{
[imageView setAnimationImages:[NSArray arrayWithObjects:[imageView image], [self imageForState], nil]];
imageView.animationDuration = 2.0;
[imageView startAnimating];
save.state++;
}
我的问题是,1.)动画永远持续下去(当我将 imageView.animationRepeatCount 设置为 1 时,我再次回到第一张图像)和 b.)动画不平滑;就像我会使用“setImage”一样;
我做错了什么?
I want to smothly animate an image in an UIImageView to turn into the next one within one second like UIModalTransitionStyleCrossDissolve does.
Currently, I've got an UIImageView * called "imageView" and a function which is called "imageForState" which returns me a UIImage * for the correct image.
So what I want to do is to animate the image A smoothly into image B if there is one.
Currently, my function is like that:
- (UIImage *) imageForState{
NSLog(@"state: %d", [save state]);
switch ([save state]) {
case 0:
case 1:
return [UIImage imageNamed:@"Sakuya_Debug.PNG"];
case 2:
return [UIImage imageNamed:@"Sakuya_2_Debug.PNG"];
default:
return NULL;
//Never called
}
}
-(void) tap{
[imageView setAnimationImages:[NSArray arrayWithObjects:[imageView image], [self imageForState], nil]];
imageView.animationDuration = 2.0;
[imageView startAnimating];
save.state++;
}
My problem is, that 1.) the animation goes on forever (when I set imageView.animationRepeatCount to 1, I end up at the first image again) and b.) the animation is not smooth; just like I would have used "setImage";
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议使用两个 imageView 和一个动画块来实现。在下面的示例中,我假设有两个大小为 100 像素的方形图像。如果将两个 imageView 添加为子视图,请确保将 imageB 添加在 imageA 之后,以便覆盖它。
初始化 imageViews:
Blend 方法:
I suggest doing it with two imageViews and an animation block. In the following example I assume two square images with a siza of 100px. If you add the two imageViews as subviews make sure that imageB is added after imageA so it covers it.
Init the imageViews:
Blend method: