在两个UIButton图像之间淡入淡出 [英] fade between two UIButton images

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

问题描述

我希望在两个UIButton图像之间淡入淡出,以便在UITableView中设置收藏夹。

i want to fade between two UIButton images for the purpose of setting favorites in a UITableView.

目前转换完成没有效果 - 它只是直接更改图像点击/触摸:

Currently the transition is done without effect - it just changes the images directly on click/touch:

trans_img = [UIImage imageNamed:@"fav_on.png"];

NSArray *subviews = [owningCell subviews];
UIButton *favbutton = [subviews objectAtIndex:2];

favbutton.imageView.animationImages =
[NSArray arrayWithObjects:trans_img,
 nil];

[favbutton.imageView startAnimating];

我发现的一切都是UIViews之间的过渡:(

Everything I found was a transition between UIViews :(

如果图像fav_off平滑地变为fav_on而另一种方式像fadein / fadeout那样圆形会很好。

It would be nice if the image fav_off gets smoothly changed into fav_on and the other way round like a fadein/fadeout.

推荐答案

你可以尝试转换像这样的alpha值来获得你想要的效果:

You could try to transition the alpha values like this to get the effect that you want:

trans_img = [UIImage imageNamed:@"fav_on.png"];

NSArray *subviews = [owningCell subviews];
UIButton *favbutton = [subviews objectAtIndex:2];
[UIView animateWithDuration:0.5 animations:^{
    favbutton.alpha = 0.0f;
} completion:^(BOOL finished) {
    favbutton.imageView.animationImages = [NSArray arrayWithObjects:trans_img,nil];
    [favbutton.imageView startAnimating];
    [UIView animateWithDuration:0.5 animations:^{
        favbutton.alpha = 1.0f;
    }];
}];

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

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