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 图像之间淡入淡出
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- URL编码Swift iOS 2022-01-01
- UITextView 内容插图 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01