在UIBarButtonitem类型的对象上找不到属性层

use*_*474 4 ios

我试图将此动画应用于UIBarButtonItem:

CABasicAnimation *theAnimation;
    theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
    theAnimation.duration=1.0;
    theAnimation.repeatCount=HUGE_VALF;
    theAnimation.autoreverses=YES;
    theAnimation.fromValue=[NSNumber numberWithFloat:1.0];
    theAnimation.toValue=[NSNumber numberWithFloat:0.5];
    [plusbutton.layer addAnimation:theAnimation forKey:@"animateOpacity"];
Run Code Online (Sandbox Code Playgroud)

但是我在最后一行代码的标题中报告了错误.如何访问barbuttonItem的图层?

jrt*_*ton 6

条形按钮项不是视图,也没有图层.

假设您没有在系统项上尝试此操作,请customView改为访问项目的图层.