Ios 编辑时是否有方法仅激活搜索栏上的“取消”按钮?

Ios 编辑时是否有方法仅激活搜索栏上的“取消”按钮?,ios,swift,uisearchbar,Ios,Swift,Uisearchbar,我知道您可以使用文本字段上的“清除”按钮执行此操作,如下所示: searchController?.searchBar.searchTextField.clearButtonMode=.whileEditing 但是搜索栏上的“取消”按钮有类似的功能吗 searchController?.searchBar.showsCancelButton=true//此选项存在 searchController?.searchBar.cancelButtonMode=.WhileEdit//我找不到这个

我知道您可以使用文本字段上的“清除”按钮执行此操作,如下所示:

searchController?.searchBar.searchTextField.clearButtonMode=.whileEditing
但是搜索栏上的“取消”按钮有类似的功能吗

searchController?.searchBar.showsCancelButton=true//此选项存在
searchController?.searchBar.cancelButtonMode=.WhileEdit//我找不到这个


谢谢大家!

如果您不希望在用户实际点击搜索控制器的搜索栏之前显示搜索栏,请不要为“取消”按钮添加任何代码。默认行为是在用户激活搜索之前不显示“取消”按钮

只需删除设置或更改“取消”按钮所需的任何代码

从iOS 13开始,您可以使用
UISearchController
automaticallyShowsCancelButton
属性,但在iOS中它默认为
true
。在Mac Catalyst下,它似乎默认为
false