在iphone中淡出图像动画 [英] fade out image Animation in iphone

查看:118
本文介绍了在iphone中淡出图像动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

iphone淡出图像

如何实现淡出动画到一组图像(图像阵列)。图像将逐一显示。当我使用下面给出的代码时,它将只显示一个简单的幻灯片放映。

How can implement fading out animation in to a set of images(array of images). Images will appear one by one. when i using the code given below it will show only a simple slide show.

NSArray *imagearray = [NSArray arrayWithObjects:
                             [UIImage imageNamed:@"image1.png"],
                             [UIImage imageNamed:@"imag2.png"],[UIImage imageNamed:@"imag3.png"],[UIImage imageNamed:@"imag4.png"],[UIImage imageNamed:@"imag5.png"],[UIImage imageNamed:@"imag6.png"],[UIImage imageNamed:@"imag7.png"],nil];
imageview.animationImages=imagearray;


imageview.animationDuration = 10.00;  

imageview.animationRepeatCount = 0;

[imageview startAnimating];

如何实现淡化效果?

推荐答案

请访问此堆栈溢出问题 iphone淡入淡出图片

Please visit this stack overflow question its iphone fading of images

- (void)viewDidLoad {
        imgView.animationImages=[NSArray arrayWithObjects:  
                                 [UIImage imageNamed:@"lori.png"],
                                 [UIImage imageNamed:@"miranda.png"],
                                 [UIImage imageNamed:@"taylor.png"],
                                 [UIImage imageNamed:@"ingrid.png"],
                                 [UIImage imageNamed:@"kasey.png"], 
                                 [UIImage imageNamed:@"wreckers.png"], nil];



        imgView.animationDuration=20.0;
        imgView.animationRepeatCount=0;
        [imgView startAnimating];
        [self.view addSubview:imgView];
        [imgView release];
        //The timers time interval is the imageViews animation duration devided by the number of images in the animationImages array. 20/5 = 4 
        NSTimer *timer = [NSTimer timerWithTimeInterval:4.0 
                                                  target:self 
                                                selector:@selector(onTimer) 
                                                userInfo:nil 
                                                 repeats:YES];

        [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
        [timer fire];

        [super viewDidLoad];
    }

    //It is important that the animation durations within these animation blocks add up to 4 
    //(the time interval of the timer). If you change the time interval then the time intervals 
    //in these blocks must also be changed to refelect the amount of time an image is displayed. 
    //Failing to do this will mean your fading animation will go out of phase with the switching of images.   

    -(void)onTimer{
            [UIView animateWithDuration:3.0 animations:^{
                imgView.alpha = 0.0; 
            }];
            [UIView animateWithDuration:1.0 animations:^{
                imgView.alpha = 1.0; 
            }];
        }

这篇关于在iphone中淡出图像动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆