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?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With