像垃圾桶动画这样的解决方案
我想将未记录的垃圾桶动画放入我的程序中。电话 方法是:
+ (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 {
}
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:
- index
- duration
- target
- selector
?
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 {
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您不需要为此执行任何未记录的内容,只需创建一个自定义
UIButton
即可。下载UIKit Artwork Extractor,您将找到垃圾桶动画的帧,如下所示以及UIBarButtonItem
背景。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 theUIBarButtonItem
background.您需要在连接到 IBOutlet 的工具栏上调用它,而不是在类上调用它。例如:
You need to call it on the toolbar connected to your IBOutlet as opposed to the class. E.g.:
您可能会在这里找到答案:https://stackoverflow.com/a/5101910/796103
You will probably find the answer here: https://stackoverflow.com/a/5101910/796103
这可能是因为您的目标设置为trashButtonItem。目标是将 didFinishSelector 发送到的对象。尝试将目标设定为自我。另外,根据 http://iphonedevwiki.net/index.php/UIToolbar 这不是类方法,因此您需要将 [UIToolbar 替换为实际的工具栏对象。
在你的 didFinishSelector 回调中,我想你再次调用该方法,垃圾桶将关闭。
祝你好运。
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.
这种“未记录”的方法记录在此处: http://iphonedevwiki.net/index.php/UIToolbar
它被记录为实例方法而不是类方法,这解释了您在异常中收到的错误消息。
@jrtc27 已正确回答了问题,因为应该将其发送到 UIToolbar 实例。从您对评论的回复来看,您似乎没有更改类类别来协助编译器。请尝试以下操作:
然后使用:
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:
And then use:
我认为如果您知道如何实现
suckEffect
,那么您就可以使用工具栏进行一些黑客操作。基本上,所有官方控件都是UIView的子类,因此您可以找到UIToolBar实例的视图层次结构。
为什么我们要打扰视图层次结构?
答案是,根据我们的需要隐藏某个视图,或者添加一个子视图。
接下来做什么
可能性?
我以前没有这样做过,但我认为这是一个可能的解决方案,因为创建带有打开/关闭/摇动动画的垃圾桶视图很容易。
风险?
不管怎样,这个解决方案就像某种
不触及私有API的黑客
,风险由您自己承担。祝你好运。
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.
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
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.