Reputation: 3960
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
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
fromUIView
. Remember to use it in DEBUG configuration.
The answer is, to hide certain view, or to add a subview as we want.
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.
Anyway, this solution is like some kind of hacking without touching the private api
, the risk is on your own.
Good luck.
Upvotes: 1
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
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
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
Reputation: 10776
You will probably find the answer here: https://stackoverflow.com/a/5101910/796103
Upvotes: 1
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