这里基本上发生的是我正在向 UIBarButtonItem 添加一个自定义 View ,我需要将它旋转 45deg ,如果旋转 90deg 或 180 则旋转效果很好,但是当它小于 90 时对象得到变形,并且在 45deg 上对象消失。 以下是按钮和动画的片段。
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.
我想这对你有帮助。
关于iOS UIImageView 旋转后消失 M_PI_4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14052057/