在imageview中淡出幻灯片. xCode 4.2

前端之家收集整理的这篇文章主要介绍了在imageview中淡出幻灯片. xCode 4.2前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在使用淡入淡出效果的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秒的延迟中,我现在想要的是每次出现图像时使它们淡入和淡出,对此有何建议?

在此先感谢您的帮助

解决方法

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

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

猜你在找的Xcode相关文章