我已经找到了向 View 、按钮添加手势的方法,但对此一无所知:(
这就是我正在尝试做的事情。 点击加号按钮添加标签。但是点击并按住同一个加号按钮可以调出一个操作表来添加标签组或标签。问题是向 UIBarButtonItem 提供手势。
这就是我初始化按钮的方式:
[self.navigationItem setPrompt: @"Tags"];
[self.navigationItem setRightBarButtonItem: [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemAdd target: self action: @selector( pressedNavRight:)] animated: YES];
[self.navigationItem setLeftBarButtonItem: [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemEdit target: self action: @selector( pressedNavLeft:)] animated: YES];
最佳答案
UIView *buttonItemView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 30)];
buttonItemView.backgroundColor = [UIColor blackColor];
UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
[buttonItemView addGestureRecognizer:tapGes];
UILongPressGestureRecognizer *longPressGes = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
[buttonItemView addGestureRecognizer:longPressGes];
UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:buttonItemView];
self.navigationItem.rightBarButtonItem = barItem;
关于ios - 在 UIBarButtonItem 上添加手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31644275/