谢谢, O.Z
@huesforalice 是正确的——最干净的方法是创建自己的UIActionSheet替代品。基本上有三种选择:
真正的替代品:创建一个UIActionSheet子类,使其与“UIActionSheetDelegate”协议兼容。这将允许您像使用UIActionSheet一样使用它,但找出何时以及为什么UIActionSheet会调用委托方法实现可能是一个昂贵的过程。
甚至可以更进一步,扩展该协议。这将为您提供更多可能性,如何使用它(即允许通过新协议方法使用选择器),但也将更加困难。
最简单的方法是创建一个完全独立于UIActionSheet及其协议的实现方式——但它不会取代真正的UIActionSheet,意味着您不能将其放入项目中并期望它能正常工作。但是你会拥有最高的自由度。
我建议选择第三种方法。我发现了一个这样的项目。但要注意:它向您展示了如何通用地做到这一点,但是具有一些糟糕的底层设计决策:
It uses a method
- (void) addButtonWithTitle: (NSString*) buttonTitle buttonId: (NSInteger) buttonId textColor: (UIColor*) textColor textShadowColor: (UIColor*) textShadowColor backgroundColor: (UIColor*) buttonBackgroundColor increasedSpacing: (BOOL) spacing
Instead — IMHO — it should be
- (void) addButton: (UIButton*) button;
So you can add buttons with different designs more flexible, and don't depend for a section id, what is totally unnecessary, as the object has its own identity as an object already.
The method [actionSheet showWithAnimation:YES];
should be called
show
or showAnimated:
as …withAnimation:
usually takes a block to perform a custom animation.
使用UIActionSheet和文档中记录的方法是不可能实现的。您可以编写自己的actionsheet,然后将其添加到主窗口并动画滑动。可能有一种方法可以通过分析actionsheet的私有视图层次结构并添加自定义按钮来实现您想要的效果,但您必须记住,私有视图层次结构可能会从一个iOS版本更改为另一个版本,因此您的应用程序可能会崩溃或甚至被苹果拒绝。