7

这里基本上发生的是我正在向 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){
}];
4

4 回答 4

2

使用锚点并导入 "QuartzCore/QuartzCore.h"

currentItem.customView.layer.anchorPoint = CGPointMake(1.0, 0.0);//it is not fixed point you have to change.

我想这会对你有所帮助。

于 2012-12-27T09:22:56.330 回答
2

If the UIImageView contentMode is set to UIViewContentModeScaleAspectFit or other scaled aspect, the rotation will cause the image to disappear.

Changing the contentMode to UIViewContentModeCenter should fix the problem.

于 2015-06-22T22:26:14.907 回答
1

我和你有完全一样的问题。我的问题是我正在viewDidLoad中进行旋转。

尝试在viewDidAppear中进行,它对我有用。

于 2013-04-30T22:11:45.217 回答
0

是的,我有同样的问题。我在 viewDidLayoutSubViews 中做了一次调度中的所有事情.....奇怪的是 CGAffineTransformMakeRotation(M_PI_2); 和 CGAffineTransformMakeRotation(M_PI); 有效,但不是这个。如果有人知道这是否是报告的问题,我会喜欢这个链接。

于 2014-05-01T14:33:04.833 回答