在imageview中淡出幻灯片。 xCode 4.2

时间:2012-03-15 01:27:05

标签: xcode uiimageview xcode4.2 fadein fadeout

我正在尝试在使用淡入淡出效果的imageview中制作幻灯片。

到目前为止,我已经做到了这一点:

    - (void)viewDidLoad
{
    [super viewDidLoad];
    animationView = [[UIImageView alloc] initWithFrame:self.view.frame];
    animationView.animationImages = [NSArray arrayWithObjects:   
                                     [UIImage imageNamed:@"photo1.jpg"],
                                     [UIImage imageNamed:@"photo2.jpg"],
                                     [UIImage imageNamed:@"photo3.jpg"], nil];

    animationView.animationDuration = 5;
    animationView.animationRepeatCount = 0;
    [animationView startAnimating];
    [self.view addSubview:animationView];
}

图像确实一个接一个地出现,延迟5秒,我现在想要的是每次出现图像时让它们淡入和淡出,对此有任何建议吗?

提前感谢您的帮助

1 个答案:

答案 0 :(得分:6)

我试图做类似的事情。我所做的是设置了一个计时器,该计时器在UIView上调用了transitionWithView UIImageView,该计时器通过我的幻灯片照片数组递增。

- (void)viewDidLoad{
[super viewDidLoad];
self.welcomePhotos = [NSArray arrayWithObjects:@"welcome_1.png",@"welcome_2.png", @"welcome_3.png", nil];
self.imageView1.image = [UIImage imageNamed:[self.welcomePhotos objectAtIndex:0]];
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(transitionPhotos) userInfo:nil repeats:YES];
}


-(void)transitionPhotos{

if (photoCount < [self.welcomePhotos count] - 1){
    photoCount ++;
}else{
    photoCount = 0;
}
[UIView transitionWithView:self.imageView1
                  duration:2.0
                   options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{ self.imageView1.image = [UIImage imageNamed:[self.welcomePhotos objectAtIndex:photoCount]]; }
                completion:NULL];    
}