fade between two UIButton images(在两个 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 图像之间淡入淡出
基础教程推荐
- 更改 UITableView 部分标题的颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- EditText 中的 setHintTextColor() 2022-01-01
- 从 UIWebView 访问元数据 2022-01-01
- Firebase 云消息传递令牌未生成 2022-01-01
- Android - 如何在runOnUiThread 中将数据传递给Runnable? 2022-01-01
- UINavigationItem 的持久 rightBarButtonItem 属性 2022-01-01
- 在 iOS 7 下 CCMenu 错位 2022-01-01
- UINavigationBar 隐藏按钮文本 2022-01-01
- 在视图控制器的宽度上水平均匀分布 UIButton 的最简单方法? 2022-01-01