这里基本上发生的是,我向UIBarButtonItem添加了一个自定义 View ,我需要将其旋转45度,如果旋转90度或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){
}];
最佳答案
使用anchorPoint并导入"QuartzCore/QuartzCore.h"
currentItem.customView.layer.anchorPoint = CGPointMake(1.0, 0.0);//it is not fixed point you have to change.
我认为这将对您有所帮助。