在我的应用程序中,我希望自定义一个当前显示用户位置的条形按钮,这样如果用户点击并按住它,它就会显示一个包含其他信息的 subview 。但是似乎我只能发送一个 Action 。这绝对是这种情况,还是有一种方法可以让我采取不止一个行动?我知道有一个子类可以启用用户方向位置(就像在 map 应用程序中一样)——我能以某种方式实现类似的功能吗?
最佳答案
创建您自己的 UIButton
并添加您想要的所有手势识别器或操作。然后使用 initWithCustomView:
创建 UIBarButtonItem
。
UIButton *btn = // create button as needed
btn.showsTouchWhenHighlighted = YES; // keep the "glow" effect
[btn addTarget:self action:@selector(someSelector) forControlEvents:someEvent];
// repeat as needed for different events/selectors
// or add gesture recognizers
UIBarButtonItem *btnItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
关于iOS:将多个操作发送到条形按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13828990/