0

我试图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是动画的?

4

1 回答 1

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;
于 2012-10-28T06:15:47.097 回答