[英]How to show two images in a view one after another and viceversa?
如何在一个接一个的视图中显示两个图像,我有两个图像名为image1和image2,当用户打开一个特定的页面,它想要显示image1然后在2秒后image1消极并显示image2然后在2秒后image2 disappers和显示image1然后继续。 我希望你能理解我的问题。如何做到这一点。 提前致谢。
你可以这样做
- (void)viewDidLoad
{
[super viewDidLoad];
[imageViewObj setImage:[UIImage imageNamed:@"Image1.png"]];
NSTimer *ImgChangeTimer = [NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(changeImage)
userInfo:nil
repeats:YES];
}
-(void)changeImage
{
if (imageViewObj.image==[UIImage imageNamed:@"Image1.png"])
{
[imageViewObj setImage:[UIImage imageNamed:@"Image2.png"]];
}
else
{
[imageViewObj setImage:[UIImage imageNamed:@"Image2.png.png"]];
}
}
你需要做的是 -
- (void)animateImages:(NSMutableArray *)ppls index:(int)i
{
i += 1;
[imageView1 setAlpha:0.0];
[imageView2 setAlpha:0.0];
[UIView animateWithDuration:0.5
delay:2
options:UIViewAnimationOptionCurveEaseIn
animations:^(void)
{
[imageView1 setAlpha:1.0];
}
completion:^(BOOL finished)
{
if(finished)
{
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^(void)
{
[imageView1 setAlpha:0.0];
[imageView2 setAlpha:1.0];
}
completion:^(BOOL finished)
{
if(finished)
{
[self animateImages index:i];
}
}];
}
}];
}
您应该使用UIImageView来执行此类动画。 将其属性animationImages
设置为图像数组。
myImageView.animationImages=[NSArray arrayWithObjects:image1,image2,nil];
myImageView.animationDuration=1; //in seconds
//myImageView.animationRepeatCount=0;
animationRepeatCount
默认为0。 您可以设置希望动画重复的次数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.