这里基本上发生的是我正在向 UIBarButtonItem 添加一个自定义视图,我需要将它旋转 45deg ,如果旋转 90deg 或 180 旋转效果很好,但是当它小于 90 时,对象会变形,并且在 45 度时,物体消失。这是按钮和动画的片段。
UIImageView * menuImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"plus.png"]];
menuButton = [[UIBarButtonItem alloc] initWithCustomView:menuImage];
UITapGestureRecognizer * tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleMenuView:)];
[menuImage addGestureRecognizer:tap1];
[menuImage setUserInteractionEnabled:YES];
[menuImage.layer setShadowColor:[UIColor blackColor].CGColor];
[menuImage.layer setShadowOffset:CGSizeMake(ShadowSizeWidth, ShadowSizeHeight)];
[menuImage.layer setShadowOpacity:ShadowOpacity];
[menuImage.layer setShadowRadius:ShadowRadius];
[self.navigationItem setRightBarButtonItem:menuButton];
旋转:
[UIView animateWithDuration:animationRotateButtonDuration delay:0.0f options:UIViewAnimationCurveLinear animations:^{
CGAffineTransform myTransform = CGAffineTransformMakeRotation(-M_PI_4);
UIBarButtonItem * currentItem = menuButton;
currentItem.customView.transform = myTransform;
}completion:^(BOOL finished){
}];