Animate UIBarButtonItem like Notes app
I just wanted to know how I could copy the trash animation of the Notes.app application. I presume this would include two images and the class of the button is开发者_StackOverflow UIBarButtonItem
.
What you're looking to do is either replace the image with an animated image or if it's already an image stack, play the animation.
Switching:
- When the button is released change the Image of the Button to an "animated" Image (array) and play the image stack.
- Once the animation
didFinishPlaying
(I think) replace the Button Image with the original static/single Image.
(This is much the same way you would easily do it in CSS/HTML.)
Animating:
- When the button is release play the current image stack
- When the animation finishes it's done.
(Basically when there is only one action: play
(on release).)
Now, if you want to do the complete animation cycle of the button and the view it becomes a bit trickier, but not too hard.
The Kitchen Sink:
- You need to have the complete image stack of the trash in it's closed state, opening animation sequence and closing animation sequence.
- The releasing on the icon, you start the first half of the animation sequences (opening animation).
- At the end of the sequence (or in parallel) you animate a transition on the view your "deleting" such as warping the view so it scales into the trash.
- When this animation finishes you send the callback/notification/message to the button saying I'm done (play closing animation)
- Then rest at the initial frame of the image stack (closed state).
I don't have the code written for you but I could write pseudo code if you'd like...
Cheers and good luck! (^_^)
In your UINavigationController, this is how you do it:
UIBarButtonItem *clearAll = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(trashMethod)];
self.navigationItem.rightBarButtonItem = clearAll;
精彩评论