gpt4 book ai didi

ios - UITapGestureRecognizer 与 UISearchBar

转载 作者:可可西里 更新时间:2023-11-01 06:22:01 24 4
gpt4 key购买 nike

我的主 ViewController 上有一个 UISearchBar。此搜索栏下方是一张 map ,因此我认为我需要第二个 ViewController 专门用于搜索。

我目前的方法是在我的主 ViewController 的搜索栏中添加一个 uitapgesturerecognizer,以便当用户点击搜索栏时,他们会无缝地重定向到第二个 View

我的代码:

UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(segueToSearch:)];

[searchBar addGestureRecognizer:singleFingerTap];

- (IBAction)segueToSearch:(id)sender {
NSLog(@"about to segue");
}

这在我执行 singleFingerTap.numberOfTapsRequired = 2 时有效,但显然我希望它可以通过单击来工作。

我的方法是否有效?如果有效,有什么问题吗?还有其他方法吗?

最佳答案

UISearchBar 有一个 UISearchbarDelegate 协议(protocol),您可以使用它在用户尝试编辑输入字段时得到通知。

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
// here you open the viewController
return NO;
}

关于ios - UITapGestureRecognizer 与 UISearchBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17262778/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com