<分区>
<分区>
我希望我的导航栏中的其中一个按钮在长按时具有不同的操作。如果它是一个普通按钮,我只是将手势识别器添加到它的 View 中,但 BarButton 没有。
线索?
最佳答案
在 UIBarButtonItem 项中添加 subview 手势是一个痛苦的过程。我在下面的代码中向您展示。它可能对你有帮助。
I like to suggest you that instead of groping around for a subview you can create the button on your own and add a button bar item with a custom view
[[[yourToolbar subviews] objectAtIndex:[[yourToolbar items] indexOfObject:yourBarButton]] addGestureRecognizer:YourGesture];
//或者您也可以尝试以下....
[self.barButtonItem.customView addGestureRecognizer:longProcess];// i didn't declare longProcess and singletap GestureRecognizer here. I hope you can do that.
[self.barButtonItem.customView addGestureRecognizer:singletap];
希望这对你有帮助..
关于iphone - 使用 UILongPressGestureRecognizer 和 UIBarButtonItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10471390/
相关文章:
iphone - iOS 应用内购买导致 > 20mb 下载
ios - 从 UICollectionViewController 导航到 UIViewController 时 UIViewController 闪烁
ios - CollectionView sizeForitemAt 方法不适用于 ios 9
objective-c - 使用核心动画旋转 UIImageView
iphone - StackScrollView 上的 "beyond bounds [0 .. 1]"消息
iphone - 当设备处于离线状态时,如何在 iPhone 上本地保存 XML 文件?