Animating only the image in UIBarButtonItem

后端 未结 4 644
暖寄归人
暖寄归人 2021-01-03 07:11

Ive seen this effect in 2 apps and I REALLY want to find how to do it.

The animation is in a UIBarButtonItem, and is only to the image. The image is a + symbol, and

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-03 07:29

    I wanted to keep the expanded tapping size that the native UIBarButtonItem view provides (such as -initWithBarButtonSystemItem:target:action: versus -initWithCustomView:).

    Here's a basic implementation of my code.

    - (void)setup {
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(navigationBarRightAction)];
    }
    
    - (void)navigationBarRightAction {
        UIView *itemView = [self.navigationItem.rightBarButtonItem performSelector:@selector(view)];
        UIImageView *imageView = [itemView.subviews firstObject];
    
        if (self.shouldRotate) {
            imageView.contentMode = UIViewContentModeCenter;
            imageView.autoresizingMask = UIViewAutoresizingNone;
            imageView.clipsToBounds = NO;
            imageView.transform = CGAffineTransformMakeRotation(M_PI_4);
    
        } else {
            imageView.transform = CGAffineTransformIdentity;
        }
    }
    

提交回复
热议问题