我想将未记录的垃圾桶动画放入我的程序中。电话 方法是:
+ (void)animateToolbarItemIndex:(unsigned)index duration:(double)duration target:(id)target didFinishSelector:(SEL)selector;
任何人都可以找出我应该插入的内容:
我的试验无效,导致错误:
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'
以下是相关代码:
@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 {
}
答案 0 :(得分:3)
您需要在连接到IBOutlet的工具栏上调用它,而不是类。 E.g:
[self.myToolbar /*(possibly just myToolbar)*/ animateToolbarItemIndex:0 duration:0.5 target:trashToolbarButton didFinishSelector:@selector(animateTrashStep2)];
答案 1 :(得分:3)
您不需要为此做任何未记录的内容,只需创建自定义UIButton
即可。下载UIKit Artwork Extractor,您将找到垃圾桶动画的帧以及UIBarButtonItem
背景。
答案 2 :(得分:1)
您可能会在这里找到答案:https://stackoverflow.com/a/5101910/796103
答案 3 :(得分:1)
这可能是因为您的目标设置为trashButtonItem。目标是将didFinishSelector发送到的对象。尝试将目标设置为自我。另外,根据http://iphonedevwiki.net/index.php/UIToolbar,这不是类方法,因此您需要将[UIToolbar替换为实际的工具栏对象。
在你的didFinishSelector回调中,我想你再次调用该方法,垃圾桶就会关闭。
祝你好运。答案 4 :(得分:1)
此处记录了这种“未记录的”方法:http://iphonedevwiki.net/index.php/UIToolbar
它被记录为实例方法而不是类方法,它解释了您在异常中收到的错误消息。
@ jrtc27已正确回答了问题,因为这应该发送到UIToolbar实例。从您对评论的回复,您似乎没有更改类类别来协助编译器。请尝试以下方法:
@interface UIToolbar (privateMethods2)
- (void)animateToolbarItemIndex:(unsigned)index duration:(double)duration target:(id)target didFinishSelector:(SEL)selector;
@end
然后使用:
[self.navigationController.toolbar animateToolbarItemIndex:0 duration:0 target:self.trashToolbarButton didFinishSelector:@selector(animateTrashStep2)];
答案 5 :(得分:1)
我想如果您知道如何执行suckEffect
,那么您可以使用工具栏进行一些黑客攻击。
基本上,所有官方控件都是UIView的子类,因此您可以找到UIToolBar实例的视图层次结构。
如果您不知道如何查找给定视图的子视图层次结构,则可以使用
- (void)recursiveDescription
中的 PRIVATE APIUIView
。请记住在 DEBUG 配置中使用它。
答案是隐藏某些视图,或添加子视图。
我之前没有这样做,但我认为这是一个可能的解决方案,因为创建垃圾桶可以通过打开/关闭/摇动动画进行查看很容易。
无论如何,这个解决方案就像某种hacking without touching the private api
,风险就是你自己。