How to animate layer shadowOpacity?

后端 未结 4 1192
生来不讨喜
生来不讨喜 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:15

    The below code work for me

    1)Add QuartzCore frame work 2)Import QuartzCore frame work

    Add the following Code in the required place

    UIImageView * glowimageview = [[[UIImageView alloc]init]autorelease];
        [glowimageview setFrame:CGRectMake(500,400,200,200)];
        [glowimageview setImage:[UIImage imageNamed:@"144.png"]];
        [sender addSubview:glowimageview];
    
        glowimageview.layer.shadowColor = [UIColor redColor].CGColor;
        glowimageview.layer.shadowRadius = 10.0f;
        glowimageview.layer.shadowOpacity = 1.0f;
        glowimageview.layer.shadowOffset = CGSizeZero;
    
        CABasicAnimation *shadowAnimation = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
        shadowAnimation.duration=1.0;
        shadowAnimation.repeatCount=HUGE_VALF;
        shadowAnimation.autoreverses=YES;
        shadowAnimation.fromValue = [NSNumber numberWithFloat:1.0];
        shadowAnimation.toValue = [NSNumber numberWithFloat:0.0];
        [glowimageview.layer addAnimation:shadowAnimation forKey:@"shadowOpacity"];
    

    It will works. Change the format of the code as per your requirement

提交回复
热议问题