iPhone图像褪色 [英] iphone fading of images

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

问题描述

我想在图像视图中显示图像并在5秒钟后淡出图像并显示下一张图像吗?图像存储在数组对象中...我能够在5秒钟后成功在图像之间进行转换seconds.我想要的是在5秒钟后淡出第一张图像,并显示下一个在无限循环中发生的图像...下面是代码,它对于图像之间的正常过渡非常有效..wat我想要的是图片的褪色...并在下面的代码中添加褪色过渡

wat i want is to show an image in image view and fade the image after 5 seconds and show the next image .the images are stored in an array objects...i was able to make a successful transition between images after 5 seconds.what i want is to fadeout the first image after 5 seconds and show the next one this got to happen in an infinite loop...below is the code and it works really good for normal transition between images..wat i want is fading of images...and were to add fading transition in the below code

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



    [super viewDidLoad];
}

推荐答案

您可以使用重复的NSTimer调用特殊方法,该方法可以将图像视图的alpha属性连续地从0.0设置为1.0.这是我写的一些有效的代码:

You can use a repeating NSTimer to call a special method which animates the image views alpha property from 0.0 to 1.0 continuously. Here is some code I have written which works:

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

如果您希望淡入淡出的持续时间从5秒而不是4持续5秒,则需要将图像视图animationDuration属性增加到25,然后在两个块中增加淡入淡出的动画持续时间,以使总淡入淡出时间= 5.

If you want the fade duration to last for 5 seconds instead of 4, you need to increase your image views animationDuration property to 25, and then increase the fade animation durations in the two blocks such that the sum fade time = 5.

这篇关于iPhone图像褪色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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