How to animate layer shadowOpacity?

后端 未结 4 1152
生来不讨喜
生来不讨喜 2021-01-30 10:35

I have a view on which I\'ve set the layerOpacity to 1.

    theView.layer.shadowOpacity = 1.0;

This looks fine when the view is farther down th

4条回答
  •  离开以前
    2021-01-30 11:17

    This will work properly:

    #import 
    
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
    anim.fromValue = [NSNumber numberWithFloat:1.0];
    anim.toValue = [NSNumber numberWithFloat:0.0];
    anim.duration = 1.0;
    [vv.layer addAnimation:anim forKey:@"shadowOpacity"];
    vv.layer.shadowOpacity = 0.0;
    

    For Swift 3.0:

     let animation = CABasicAnimation(keyPath: "shadowOpacity")
     animation.fromValue = layer.shadowOpacity
     animation.toValue = 0.0
     animation.duration = 1.0
     view.layer.add(animation, forKey: animation.keyPath)
     view.layer.shadowOpacity = 0.0
    

提交回复
热议问题