我想改变我的UIView
带有过渡动画的背景颜色。例如,如果视图是红色的,我将其更改为蓝色。蓝色将从屏幕底部向上滑动到顶部并充满整个屏幕。我想通过制作一个来做到这一点UIView
具有相同大小和所需颜色,然后将其从屏幕外一直动画到顶部。但这似乎不是一个非常优雅的方法。有更好的方法吗?任何积分将不胜感激。谢谢!
尝试这个:
CALayer *layer = [CALayer layer];
layer.frame = CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height);
layer.backgroundColor = [UIColor blueColor].CGColor;
[self.view.layer addSublayer:layer];
CABasicAnimation *animation = [CABasicAnimation animation];
animation.keyPath = @"position.y";
animation.byValue = @(-self.view.bounds.size.height);
animation.duration = 1;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
[layer addAnimation:animation forKey:@"Splash"];
你可以试试这个:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:self.view cache:NO];
self.view.layer.backgroundColor = [UIColor blueColor].CGColor;
[UIView commitAnimations];
我还有另一个使过渡顺利的建议:
[UIView animateWithDuration:2.0 animations:^{
self.view.layer.backgroundColor = [UIColor blueColor].CGColor;
} completion:nil];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)