objective-c – iphone淡化图像

objective-c – iphone淡化图像,第1张

概述我想要的是在图像视图中显示图像并在5秒后淡化图像并显示下一个图像.图像存储在数组对象中…我能够在5秒后在图像之间成功转换.我想要的是在5秒后淡出第一个图像并显示下一个在无限循环中发生…下面是代码,它对图像之间的正常过渡非常有用..我想要的是图像的褪色…并在下面的代码中添加淡入过渡 - (void)viewDidLoad { imgView.animationImages=[NSArray 我想要的是在图像视图中显示图像并在5秒后淡化图像并显示下一个图像.图像存储在数组对象中…我能够在5秒后在图像之间成功转换.我想要的是在5秒后淡出第一个图像并显示下一个在无限循环中发生…下面是代码,它对图像之间的正常过渡非常有用..我想要的是图像的褪色…并在下面的代码中添加淡入过渡

- (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.以下是我编写的一些代码:

- (voID)vIEwDIDLoad {    imgVIEw.animationImages=[NSArray arrayWithObjects:                               [UIImage imagenamed:@"lori.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秒,则需要将图像视图animationDuration属性增加到25,然后增加两个块中的淡入淡出动画持续时间,使得淡入淡出时间= 5.

总结

以上是内存溢出为你收集整理的objective-c – iphone淡化图像全部内容,希望文章能够帮你解决objective-c – iphone淡化图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1061077.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存