这里基本上发生的是我正在向UIBarButtonItem添加一个自定义视图,我需要将其旋转45度,如果旋转90度或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.
我认为这对你有所帮助.