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){ }];
Noob
source share