我正在尝试在UINavigationBar
上捕捉触摸事件。当用户点击它时,我计划执行操作。但是,我似乎无法捕获此组件上的触摸事件。我的代码看起来像这样......
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self.navigationController.navigationBar action:nil];
singleTap.numberOfTapsRequired = 1;
singleTap.delegate = self;
[self.navigationController.navigationBar addGestureRecognizer:singleTap];
但是,每当我点击导航栏时,我的选择器都不会被调用。我在这里做错了吗?我是否需要做一些特殊操作来捕获此控件上的触摸事件?
答案 0 :(得分:1)
尝试:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSomething)];
singleTap.numberOfTapsRequired = 1;
//singleTap.delegate = self;
[self.navigationController.navigationBar addGestureRecognizer:singleTap];
-(void) doSomething
{
NSLog(@"doSomething");
}