在IOS中在闪屏上淡出多个图像

时间:2013-03-08 13:33:21

标签: iphone ios ios5 uiimageview

我正在尝试为启动画面设置多个图像的动画。我正在显示3个图像作为启动画面第一个是启动画面的默认图像比使用Ui-imageview我在我的Imageview上显示第2个和第3个。

我希望在更改启动画面时淡出图像。我尝试了NSTimmer解决方案,但它显示我直接第三张图像和缅因屏幕比我尝试过这个解决方案后,但它一个接一个地显示我的第二和第三张图像2次。 任何帮助表示赞赏

编辑/ - Nikki建议我一些解决方案,但我感到困惑,哪个地方我取消隐藏我的第二个图像视图? 这是我的代码

backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
backgroundImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
backgroundImageView.image=[UIImage imageNamed:@"SPLASHSCREEN-2.png"];
backgroundImageView2 = [[UIImageView alloc] initWithFrame:self.view.bounds];
backgroundImageView2.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
backgroundImageView2.image=[UIImage imageNamed:@"SPLASHSCREEN-3.png"];
[self.view addSubview:backgroundImageView];
[self.view addSubview:backgroundImageView2];
[backgroundImageView2 setHidden:YES];
[self performSelector:@selector(performTransition) withObject:nil afterDelay:1.0];

-(void)performTransition
   {
CATransition *animation3 = [CATransition animation];
[animation3 setDuration:3.0f];
[animation3 setType:kCATransitionReveal];
[animation3 setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[backgroundImageView layer] addAnimation:animation3 forKey:@"SwitchToView"];
[backgroundImageView setHidden:YES];
[backgroundImageView2 setHidden:NO];//No animation happen while changing the image view
}

1 个答案:

答案 0 :(得分:1)

你可以创建在开始时显示的两个ImageView并首先隐藏它们。只需将代码编写为动画:

-(void)performTransition
{  
  CATransition *animation3 =  [CATransition animation];
  [animation3  setDuration:3.0f];
  [animation3  setType:kCATransitionReveal];
  [animation3  setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
  [[backgroundImageView2  layer] addAnimation:animation3 forKey:@"SwitchToView"];
  [backgroundImageView  setHidden:YES];
  [backgroundImageView2  setHidden:NO];//No animation happen while changing the image view
} 

并将ImageView设置为动画,同时取消隐藏。可以通过更改[animation3 setType:kCATransitionReveal];的值来更改动画类型。 请记住导入:#import<QuartzCore/QuartzCore.h>

用于使用动画隐藏上一个ImageView并使用动画显示下一个ImageView,您可以在函数内编写代码,并可以使用performSelector调用该函数,并可以添加所需的时间间隔。