如何将动画设置为UIImageView?

编程入门 行业动态 更新时间:2024-10-09 12:26:29
本文介绍了如何将动画设置为UIImageView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何为UIImageView提供动画。 我有以下动画代码。但不适用于imageview

How to give animation to UIImageView. I have a following code for animation .but not working for imageview

MyImage=[[UIImageView alloc] initWithFrame:CGRectMake(10, 57, 220,140)]; MyImage.image=[UIImage imageNamed:@"image.png"]; MyImage.userInteractionEnabled = YES; [self.view addSubview:MyImage]; [UIView beginAnimations : nil context : nil]; [UIView setAnimationCurve : UIViewAnimationCurveLinear]; [UIView setAnimationDuration : 1.00]; UIView setAnimationTransition : UIViewAnimationTransitionFlipFromLeft forView : MyImage cache : YES]; [UIView commitAnimations];

任何人都有这个想法让我知道..谢谢

Anybody have idea let me know ..Thanks

推荐答案

UIView setAnimationTransition : UIViewAnimationTransitionFlipFromLeft forView : MyImage cache : YES];

代码前的 [>也许这是类型错误。

Loose [ before the code? Maybe it's the type mistake.

我想你可能会喜欢这个,基于块的动画更好;):

And I think you may like this one, block-based animation is better ;) :

[UIView transitionFromView:self.view toView:MyImage duration:1.0f options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];

这里的代码片段效果很好:

And here's code snippet that works well:

MyImage=[[UIImageView alloc] initWithFrame:CGRectMake(10, 57, 220,140)]; MyImage.image=[UIImage imageNamed:@"NTCHomeMainPic.png"]; MyImage.userInteractionEnabled = YES; // [self.view addSubview:MyImage]; // You don't need to add it as subview, but never mind [UIView transitionFromView:self.view toView:MyImage duration:1.0f options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];

编辑:

您需要创建一个新视图并向其添加 MyImage 。下面的新版本:

UIView * newView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)]; [newView setBackgroundColor:[UIColor whiteColor]]; UIImageView * MyImage=[[UIImageView alloc] initWithFrame:CGRectMake(10, 57, 220,140)]; MyImage.image=[UIImage imageNamed:@"NTCHomeMainPic.png"]; MyImage.userInteractionEnabled = YES; [newView addSubview:MyImage]; [UIView transitionFromView:self.view toView:newView duration:1.0f options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];

更多推荐

如何将动画设置为UIImageView?

本文发布于:2023-11-25 21:43:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631457.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   如何将   动画   UIImageView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!