一切都是默认的.导航栏是半透明的.单击搜索栏时,导航栏会向上滑动.现在,当您关闭搜索时,它会重新滑入,这会在搜索和导航栏之间产生白色差距:
是什么原因导致了这个以及如何解决它?我使用的是swift,iOS8.1和xcode6.1
我唯一能做的就是将表视图的视图背景设置为蓝色.但这会产生负面影响,当表视图为空时,所有内容都将变为蓝色.
解决方法 从 the code you posted on GitHub我可以找到一种方法来避免差距,显然是一个动画时间问题.在你的FirsttableVIEwController.swift中,你需要注册为UISearchbar的委托,然后在searchbar解散时(尽快文本编辑结束)使用委托方法searchbarTextDIDEndEditing触发自己早先出现的navigationbar:
这是你的最后一个swift文件,增加了2个:第3行的UISearchbarDelegate和最后的函数searchbarTextDIDEndEditing:
import UIKitclass FirsttableVIEwController: UItableVIEwController,UISearchbarDelegate { var entrIEs: NSArray = ["Foo","bar"]; overrIDe func tableVIEw(tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int { return self.entrIEs.count } overrIDe func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell { let cell = self.tableVIEw.dequeueReusableCellWithIDentifIEr("cell",forIndexPath: indexPath) as UItableVIEwCell cell.textLabel?.text = entrIEs[indexPath.row] as? String return cell } overrIDe func tableVIEw(tableVIEw: UItableVIEw,dIDSelectRowAtIndexPath indexPath: NSIndexPath) { performSegueWithIDentifIEr("test",sender: nil) } // Fix searchbar disappear BUG func searchdisplayControllerDIDEndSearch(controller: UISearchdisplayController) { self.tableVIEw.insertSubvIEw(self.searchdisplayController!.searchbar,aboveSubvIEw: self.tableVIEw) } func searchbarTextDIDEndEditing(searchbar: UISearchbar) { self.navigationController?.setNavigationbarHIDden(false,animated: true) }}
编辑 – 通过调整IB中的正确布局选项,两个视图控制器都可以工作.
第一:tableVIEw的3个选中选项位于绘图:不透明清除图形上下文自动调整子视图
第二:对于VIEwController本身,扩展边缘选中的选项是:在不透明条形下的底栏下
第三:关于UISearchbar代表团的上述代码……
总结以上是内存溢出为你收集整理的ios – UISearchBar解除动画问题全部内容,希望文章能够帮你解决ios – UISearchBar解除动画问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)