我有一个UITabBarController
作为我的应用程序的rootViewController。启动下载后,我会在最后一个标签上显示徽章并使用脉冲颜色显示正在进行下载:
- (void)incrementBadgeValue {
UITabBarItem *moreTabBarItem = [self.tabBar.items lastObject];
moreTabBarItem.badgeValue = @"↓";
self.originalColor = moreTabBarItem.badgeColor.copy;
UIColor *toColor = [UIColor darkGrayColor];
NSTimeInterval duration = 1.5f;
[UIView animateWithDuration:duration
delay:0.0
options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut
animations:^{
moreTabBarItem.badgeColor = toColor;
} completion:^(BOOL finished) {
if (finished) {
moreTabBarItem.badgeColor = self.originalColor;
}
}];
}
这非常有效,直到窗口上显示另一个UIViewController
,或者用户离开并返回到应用。在这些情况下,动画暂停/停止。
在这种情况下如何继续播放此动画?
答案 0 :(得分:0)
我有同样的问题。要解决它
UITabBarController
(名称CustomTabBarController
)viewWillAppear
方法以在窗口上显示另一个UIViewController时停止动画,或者用户离开并返回应用viewDidDisappear
方法以检查并在需要时继续动画。CustomTabBarController
内。创建delegate
并在控制器类上使用它<强> CustomTabBarController 强>
@protocol CustomTabBarDelegate<NSObject>
- (void)tabBarWillAppear;
- (void)tabBarDidDisappear;
@end
@interface CustomTabBarController : UITabBarController
@property(nonatomic, weak) id<CustomTabBarDelegate> customDelegate;
@end
@implementation CustomTabBarController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.customDelegate tabBarWillAppear];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self.customDelegate tabBarDidDisappear];
}
@end
<强> YourViewController 强>
@interface YourViewController () <CustomTabBarDelegate>
@end
@implementation YourViewController
- (void)viewDidLoad {
[super viewDidLoad];
[(CustomTabBarController*)self.tabBarController setCustomDelegate:self];
}
- (void)tabBarWillAppear {
if (/*Still need animation*/) {
[self incrementBadgeValue];
}
}
- (void)tabBarDidDisappear {
// Remove your animation
}
@end