[英]iOS UIImageView disappears after rotation M_PI_4
这里基本上发生的是我正在向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.
我认为这对你有所帮助。
我和你有完全相同的问题。 我的问题是我在viewDidLoad中进行旋转。
尝试在viewDidAppear中执行它,它对我有用 。
如果UIImageView contentMode设置为UIViewContentModeScaleAspectFit或其他缩放方面,则旋转将导致图像消失。
将contentMode更改为UIViewContentModeCenter应该可以解决问题。
是的,我有同样的问题。 我在viewDidLayoutSubViews中执行了一次调度...... CGAffineTransformMakeRotation(M_PI_2)是奇怪的。 和CGAffineTransformMakeRotation(M_PI); 有效,但不是这个。 如果有人知道这是否是一个报道的问题我会喜欢这个链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.