像垃圾桶动画这样的解决方案

发布于 2024-12-15 11:11:13 字数 1146 浏览 4 评论 0原文

我想将未记录的垃圾桶动画放入我的程序中。电话 方法是:

+ (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

伪装你 2024-12-22 11:11:13

您不需要为此执行任何未记录的内容,只需创建一个自定义 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 the UIBarButtonItem background.

浮世清欢 2024-12-22 11:11:13

您需要在连接到 IBOutlet 的工具栏上调用它,而不是在类上调用它。例如:

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

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)];
情绪 2024-12-22 11:11:13

您可能会在这里找到答案:https://stackoverflow.com/a/5101910/796103

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

月依秋水 2024-12-22 11:11:13

这可能是因为您的目标设置为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.

停顿的约定 2024-12-22 11:11:13

这种“未记录”的方法记录在此处: 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)];

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)];
我最亲爱的 2024-12-22 11:11:13

我认为如果您知道如何实现 suckEffect,那么您就可以使用工具栏进行一些黑客操作。

基本上,所有官方控件都是UIView的子类,因此您可以找到UIToolBar实例的视图层次结构。

如果您不知道如何找出给定视图的子视图层次结构,您可以使用 中的 PRIVATE API - (void)recursiveDescription UIView。请记住在DEBUG配置中使用它。


为什么我们要打扰视图层次结构?

答案是,根据我们的需要隐藏某个视图,或者添加一个子视图

接下来做什么

  1. 找到你的垃圾桶的原始 UIBarButtonItem 视图
  2. 在suckEffect开始之前,隐藏它,添加一个新的垃圾桶视图,它可以做打开/关闭/摇动的动画。这一刻我认为你需要要求它做打开动画。
  3. 然后让suckEffect飞起来...
  4. suckEffect结束后,让你的视图执行关闭动画。
  5. 关闭动画完成后,删除您的视图,并重新显示原始垃圾桶视图。

可能性?

我以前没有这样做过,但我认为这是一个可能的解决方案,因为创建带有打开/关闭/摇动动画的垃圾桶视图很容易。

风险?

不管怎样,这个解决方案就像某种不触及私有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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文