渐变效果就是一个图案或者界面慢慢的发生变化,而不是瞬间的改变,渐变效果往往能使界面动画更加美观,高大上,其实代码很简单,就一个方法:
[UIView animateWithDuration:2.0f/*渐变动画的时间*/ animations:^{
//执行的动画效果,比如透明的的改变,大小的改变,颜色的改变
}];
示例代码:
1、透明的的变化如下
[UIView animateWithDuration:2.0f animations:^{
if (sender.selectedSegmentIndex == 1) {
self.myBtn.alpha = 0;
}else {
self.myBtn.alpha = 1;
}
}];
2、颜色变化如下:
[UIView animateWithDuration:2.0f animations:^{
if (sender.selectedSegmentIndex == 0) {
self.myBtn.backgroundColor = [UIColor redColor];
}else if (sender.selectedSegmentIndex == 1) {
self.myBtn.backgroundColor = [UIColor greenColor];
}else {
self.myBtn.backgroundColor = [UIColor blackColor];
}
}];
3、旋转效果:
[UIView animateWithDuration:2.0f animations : ^{
self.chooseBtn.transform = CGAffineTransformRotate(self.chooseBtn.transform,M_PI_4*0.25*random );
}];
4、翻转效果:
[UIView transitionWithView:self.chooseBtn duration:2.0f options:UIViewAnimationOptionTransitionFlipFromRight animations:nil completion:nil];