iOS UIImageView 旋转后消失 M_PI_4

标签 ios animation uiimageview rotation uibarbuttonitem

这里基本上发生的是我正在向 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/

相关文章:

ios - 动画还在,当主线程做其他事情时

java - JApplet 使用的线程分割

iOS/swift : Using touchesmoved to move UIImageView

ios - 圆角的 UIImageView 继承

ios - 标签栏按钮全灰

ios - UIViewController 上的自定义属性,如 splitViewController 或 tabBarController

android - 如何在 Android 中恢复和暂停 API 级别低于 19 的 ObjectAnimator?

ios - 将 UIImageView 放入 RSS feed 应用程序的表格单元格中

ios - UIButtons 在 ScrollView 中不起作用

ios - 在 UIView 上绘制时 UIImage 反转