gpt4 book ai didi

iphone - 如何给 UIImageView 设置动画?

转载 作者:可可西里 更新时间:2023-11-01 04:36:35 25 4
gpt4 key购买 nike

如何给 UIImageView 动画。我有以下动画代码。但不适用于 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];

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

最佳答案

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

在代码之前松动[?可能是类型错误。

而且我想您可能会喜欢这个,基于 block 的动画效果更好;):

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

下面是运行良好的代码片段:

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];

编辑:

您需要创建一个新 View 并将 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];

关于iphone - 如何给 UIImageView 设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8429183/

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