如何在一个UIBarButtonItem上添加动画呢

请支持原创, 如需转载, 请注明出处@TEASON

UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"user"] style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonClicked)] ;

animation需要添加在layer上, layer可以是单独存在, 也可以是view的子类.
利用UIBarButtonIteminitWithCustomView:方法. 生成一个自定义视图. 操作这个自定义视图, (当然, 你可以设置他为成员变量)

        m_shareImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, btSide, btSide)] ;
        m_shareImage.image = [UIImage imageNamed:@"share"] ;
        m_shareImage.contentMode = UIViewContentModeScaleAspectFit ;
        UIButton *btShare = [[UIButton alloc] init] ;
        btShare.bounds = m_shareImage.bounds ;
        [btShare addSubview:m_shareImage] ;
        [btShare addTarget:self action:@selector(rightButtonClicked) forControlEvents:UIControlEventTouchUpInside] ;
        UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithCustomView:btShare] ;

so that's it .

你可能感兴趣的:(如何在一个UIBarButtonItem上添加动画呢)