我试图在我褪色阴影的同时缩放我的UIView
,使用以下内容:
myController.view.layer.shadowOffset = CGSizeMake(0, 3);
myController.view.layer.shadowColor = [UIColor blackColor].CGColor;
myController.view.layer.shadowOpacity = 0.0;
myController.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:myController.view.bounds].CGPath;
[UIView animateWithDuration:0.3
animations:^{
//shrink the view
myController.view.transform = CGAffineTransformMakeScale(0.8, 0.8);
//fade in the shadow
myController.view.layer.shadowOpacity = 0.8;
}
completion:^(BOOL finished){
...etc
视图正确调整大小,但阴影立即显示而不是淡入。
我做错了吗?我认为shadowOpacity
是可动画的吗?
答案 0 :(得分:2)
您必须使用Core Animations为视图图层属性设置动画:
#import <QuartzCore/CAAnimation.h>
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:0.8];
animation.duration = 1.0;
[myView.layer addAnimation:animation forKey:@"shadowOpacity"];
myView.layer.shadowOpacity = 0.0;