简体   繁体   English

Swift:当SearchBar处于活动状态时,应按两次Back按钮

[英]Swift: Back button should be pressed twice while SearchBar is active

I have a UITableViewController embedded in a navigation bar and standard Search bar implementation. 我在导航栏和标准搜索栏实现中嵌入了UITableViewController。 I don't hide the navigation bar while the search bar is active. 搜索栏处于活动状态时,我不会隐藏导航栏。 The problem is that while the search bar is active, every button in the navigation bar, like a "Back" button, should be pressed twice— the first time to make the search bar inactive. 问题在于,当搜索栏处于活动状态时,应按两次导航栏中的每个按钮(例如“后退”按钮),这是第一次使搜索栏处于非活动状态。 How can I avoid that? 我该如何避免呢? Thank you. 谢谢。

add this codes on viewDidLoad 在viewDidLoad上添加此代码

    self.definesPresentationContext = true

and add this if your navigationBar is Opaque 并添加它,如果您的navigationBar是不透明的

    self.extendedLayoutIncludesOpaqueBars = true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM