T.J.
T.J.

Reputation: 3960

Solution Like Trash Can Animation

I would like to put the undocumented trash can animation in my program. The call method is:

+ (void)animateToolbarItemIndex:(unsigned)index duration:(double)duration target:(id)target didFinishSelector:(SEL)selector;

Can anyone figure out what I should plug in for:

My trials are not working resulting in the error:

2011-11-15 16:05:20.639 CNiPhone[973:707] +[UIToolbar animateToolbarItemIndex:duration:target:didFinishSelector:]: unrecognized selector sent to class 0x3f019c08
2011-11-15 16:05:20.641 CNiPhone[973:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIToolbar animateToolbarItemIndex:duration:target:didFinishSelector:]: unrecognized selector sent to class 0x3f019c08'

Here is the relevant code:

@interface UIToolbar (privateMethods2)

+ (void)animateToolbarItemIndex:(unsigned)index duration:(double)duration target:(id)target didFinishSelector:(SEL)selector;

@end

    [UIToolbar animateToolbarItemIndex:0 duration:0.5 target:trashToolbarButton didFinishSelector:@selector(animateTrashStep2)];
    [UIToolbar commitAnimations];

- (void) animateTrashStep2 {
}

Upvotes: 4

Views: 2279

Answers (6)

Tonny Xu
Tonny Xu

Reputation: 2162

I think if you know how to do the suckEffect, then you can do a little bit hacking with the toolbar.

Basically, all the official controls are a subclass of UIView, hence you can find out the view hierarchy of the UIToolBar instance.

If you don't know how to find out the subview hierarchy of a given view, you can use a PRIVATE API - (void)recursiveDescription from UIView. Remember to use it in DEBUG configuration.

Why should we bother the view hierarchy?

The answer is, to hide certain view, or to add a subview as we want.

What's next

  1. Find the origin UIBarButtonItem view of your trash can
  2. Before the suckEffect start, hide it, add a new trash can view which can do the animation of open/close/shaking. This moment I think you need to ask it to do open animation.
  3. Then let the suckEffect fly...
  4. After the suckEffect ended, ask your view to do the close animation.
  5. After the close animation is finished, remove your view, and reshow the original trash can view.

Possibility?

I haven't done it before, but I think it's a possible solution because creating an trash can view with open/close/shaking animation is easy.

Risk?

Anyway, this solution is like some kind of hacking without touching the private api, the risk is on your own.

Good luck.

Upvotes: 1

ikuramedia
ikuramedia

Reputation: 6058

This 'undocumented' method is documented here: http://iphonedevwiki.net/index.php/UIToolbar

It's documented as being an instance method and not a class method, which explains the error message you're receiving in the exception.

@jrtc27 has answered the question correctly, in that this should be sent to the UIToolbar instance instead. From your reply to the comments, it seems that you have not changed your class category to assist the compiler. Try the following instead:

@interface UIToolbar (privateMethods2)
- (void)animateToolbarItemIndex:(unsigned)index duration:(double)duration target:(id)target didFinishSelector:(SEL)selector;
@end

And then use:

[self.navigationController.toolbar animateToolbarItemIndex:0 duration:0 target:self.trashToolbarButton didFinishSelector:@selector(animateTrashStep2)];

Upvotes: 1

John Estropia
John Estropia

Reputation: 17500

You dont need to do any undocumented stuff for this, just create a custom UIButton. Download the UIKit Artwork Extractor and you'll find the frames for the trash can animation, as well as the UIBarButtonItem background.

Upvotes: 3

Daddy
Daddy

Reputation: 9035

It's probably because your target is set to trashButtonItem. The target is the object that the didFinishSelector will be sent to. Try setting the target to self. Also, according to http://iphonedevwiki.net/index.php/UIToolbar this is not a class method so you will need to replace the [UIToolbar with the actual toolbar object.

In your didFinishSelector callback I guess you call the method again and the trashcan will close.

Good luck.

Upvotes: 1

Christian Schnorr
Christian Schnorr

Reputation: 10776

You will probably find the answer here: https://stackoverflow.com/a/5101910/796103

Upvotes: 1

jrtc27
jrtc27

Reputation: 8526

You need to call it on the toolbar connected to your IBOutlet as opposed to the class. E.g.:

[self.myToolbar /*(possibly just myToolbar)*/ animateToolbarItemIndex:0 duration:0.5 target:trashToolbarButton didFinishSelector:@selector(animateTrashStep2)];

Upvotes: 3

Related Questions