Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform (rotate) a UIBarButtonItem

Does anybody know how to transform a UIBarButtonItem ?

I tried this but with no results :( It's not working on both UIBarButtonItem and its customview.

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5.0f];
CGAffineTransform myTransform = CGAffineTransformMakeRotation(M_PI_2);
UIBarButtonItem * currentItem =  [self.toolbarItems objectAtIndex:4];
currentItem.customView.transform = myTransform;
[UIView commitAnimations];

I confirm the transform works on other views (I tried with self.view).

Thanks !

like image 219
Papagalli Avatar asked Oct 05 '10 13:10

Papagalli


2 Answers

use:

UIView *view = [backItem valueForKey:@"view"];
view.transform = CGAffineTransformMakeScale(-1, 1);
like image 105
Vil Avatar answered Oct 04 '22 09:10

Vil


UIBarButtonItem does not extend UIView, so it cannot be transformed directly. You can add the UIBarButtonItem you wish to transform to a UIToolbar, transform the UIToolbar and then add the toolbar as a custom view to another UIBarButtonItem. This item can then be set as a navigation item or added to another UIToolbar.

UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(handleForwardItemTouch:)];

UIToolbar *backToolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 44, 44)] autorelease];
[backToolbar setTransform:CGAffineTransformMakeScale(-1, 1)];

UIBarButtonItem *backToolbarItem = [[[UIBarButtonItem alloc] initWithCustomView:backToolbar] autorelease];
self.navigationItem.rightBarButtonItem = backToolbarItem;
like image 36
Brody Robertson Avatar answered Oct 04 '22 09:10

Brody Robertson