在UIView中将背景颜色从一种颜色淡化为另一种颜色
如何在UIView中从一种背景颜色淡化为另一种颜色?
在javascript(jQuery)中,可以通过执行以下操作来完成:
$('body').animate({ backgroundColor: "#ff00ff"});
如果我将颜色转换为HSV会更容易吗?
编辑:
尝试使用CABasicAnimation进行操作,但由于未知原因它会闪烁白色。 :/
CABasicAnimation* fade = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
fade.fillMode = kCAFillModeForwards;
fade.removedOnCompletion = NO;
// fade.fromValue = (id)[self.view backgroundColor].CGColor;
fade.toValue = (id)[UIColor greenColor].CGColor;
[self.view.layer addAnimation:fade forKey:@"fade"];
然后我试图找到另一种方法去做,并偶然发现“隐式动画”。以下工作与一秒钟的漂亮淡出:
[UIView beginAnimations:@"fade" context:nil];
[UIView setAnimationDuration:1];
[[self view] setBackgroundColor: [UIColor greenColor]];
[UIView commitAnimations];
谢谢,StackOverflow,帮助每个人学习更多。 :)
没有找到相关结果
已邀请:
1 个回复
旦彤