IOS UIImageView disappears after rotating M_PI_4

What basically happens here is that I add a custom view to the UIBarButtonItem, and I need to rotate it 45 degrees, the rotation works fine if it is rotated 90 degrees or 180, but when it is less than 90, the object gets deformed. and at 45deg the object disappears. Here are snippets for the button and animation.

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]; 

Rotation:

 [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){ }]; 
+7
source share
4 answers

Use anchorPoint and import "QuartzCore/QuartzCore.h"

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

I think it will be useful for you.

+1
source

I had the same problem as you. My problem was that I was doing a rotation in viewDidLoad .

Try to do this in viewDidAppear , it worked for me.

+1
source

If UIImageView contentMode is set to UIViewContentModeScaleAspectFit or another scaled aspect, rotation will result in the image disappearing.

Changing the contentMode in the UIViewContentModeCenter should fix the problem.

+1
source

Yes, I had the same problem. I did everything that was in dispatching, once in viewDidLayoutSubViews ..... It is strange that CGAffineTransformMakeRotation (M_PI_2); and CGAffineTransformMakeRotation (M_PI); works, but not that. If anyone knows if this is a problem with the message, I would like a link.

0
source

All Articles