UISearchBar失去焦点时取消按钮会不可用,我们可以在UISearchBar失去焦点时(例如点击搜索,拖动滚动条等),将取消按钮isEnabled设置为true,使用KVC不会导致App Store审核被拒。
extension UISearchBar{
func setCancelButtonEnable(){
if let cancelButton
= value(forKey
: "cancelButton") as? UIButton{
cancelButton
.isEnabled
= true
}
}
}
func searchBarSearchButtonClicked(_ searchBar
: UISearchBar) {
searchBar
.resignFirstResponder()
searchBar
.setCancelButtonEnable()
}
func scrollViewWillBeginDragging(_ scrollView
: UIScrollView) {
searchBar
.resignFirstResponder()
searchBar
.setCancelButtonEnable()
}
转载请注明原文地址: https://yun.8miu.com/read-18193.html