Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make a UIBarButtonItem animation flip?

In the iPod app on the iPhone there is a UIBarButtonItem in the upper right toolbar that flips between the song and track listings for the album. When you select the button, the button itself does a flip animation.

Is there a way to do this with:

CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];

[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:[self superview] cache:YES];

Do I need to make a UIBarButtonItem with initWithCustomView vs. initWithImage to achieve this?

like image 963
Andrew Arrow Avatar asked May 07 '10 00:05

Andrew Arrow


2 Answers

The UIBarButtonItem is not a child of any UIView class, therefore cannot be animated. Such animations (as if Apple's Maps or iPod) are, probably, private APIs.

However, a rough workaround this is creating a UIBarButtonItem using initWithCustomView, and then animate the flip inside that view. However, this might be quite cumbersome - you'll need to provide your own border graphics for the button.

Hope this was helpful, Paul

like image 117
Pawel Avatar answered Oct 03 '22 08:10

Pawel


I've done something similar. I have a UIBarButtonItem which flips horizontally when a textfield gains focus. In order to achieve this I used a button with a custom UIView inside which I put a transparent toolbar containing my done bar button item.

In order to flip the buttons I use the transitionFromView:toView:options:completion: methods with the old and new toolbar as the from and to views.

It's a bit overhead, but you can stick to the apple default bar buttons.

like image 24
mAu Avatar answered Oct 03 '22 08:10

mAu