在两个 UIButton 图像之间淡入淡出

fade between two UIButton images(在两个 UIButton 图像之间淡入淡出)

本文介绍了在两个 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 并且反过来像淡入/淡出一样,那就太好了.

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 图像之间淡入淡出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在两个 UIButton 图像之间淡入淡出

基础教程推荐