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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)