我有一个 UISlider ,并在滑块的曲目中成功添加了一些子视图。我想用动画逐个逐个更改子视图的颜色。
答案 0 :(得分:0)
此示例可能对您有所帮助,抱歉第一次没有完全理解您:
typedef void (^VoidBlock)(void);
@interface ClassName ()
@property (nonatomic, strong)VoidBlock animationBlock;
@end
- (void)runAnimation
{
NSArray *views = @[view1, view2, view3];
__weak LibraryViewController *weak_self = self;
__block NSInteger currentView = 0;
__block NSUInteger colorNumber = 0;
self.animationBlock = ^{
[UIView animateWithDuration:1 animations:^{
if (colorNumber == 0){
[views[currentView] setBackgroundColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:1]];
}
else if (colorNumber == 1){
[views[currentView] setBackgroundColor:[UIColor colorWithRed:0 green:1 blue:0 alpha:1]];
}
else {
[views[currentView] setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:1 alpha:1]];
}
} completion:^(BOOL finished) {
currentView += 1;
if (currentView == views.count){
currentView = 0;
colorNumber += 1;
if (colorNumber == views.count)
colorNumber = 0;
}
weak_self.animationBlock();
}];
};
self.animationBlock();
}