我找到了为视图,按钮添加手势的方法,但没有任何内容:(
这就是我想要做的事情。在加号按钮上点按以添加标记。但点击并按住相同的加号按钮以显示一个操作表,以添加标签组或标签。问题是给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];
答案 0 :(得分:3)
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;