导航栏后面的搜索栏

时间:2016-03-06 12:18:38

标签: ios swift autolayout uinavigationbar

给出3个控制器:A,B,C A有一个隐藏的导航栏。通过StoryboardReference调用控制器B. 控制器B在viewDidLoad上显示导航栏。它有一个搜索栏和一个collectionView。查看我的故事板的屏幕截图A.如果单击一个单元格,则调用控制器C.

问题: 如果A调用B,则搜索栏位于导航栏后面(屏幕截图B)。它出现在从C到B的过渡(截图C)。

导航栏已经是半透明的。有什么想法吗?

修改

我意识到我的动画过渡导致了我的问题。

也许您可以发现错误?

nil

2 个答案:

答案 0 :(得分:1)

我相信我在我的应用中遇到了一些类似的问题,但由于你无法控制的所有事情而陷入困境。我的解决方案是在导航栏中放置一个搜索图标,然后将搜索控制器向下滑动到导航栏上,使其远离表格/滚动视图。这是我的实现(应该是完整的)

import UIKit

class tvc: UITableViewController, UISearchBarDelegate, UISearchControllerDelegate {

var searchController:UISearchController!

@IBAction func startSearch() {
    self.navigationController?.presentViewController(self.searchController, animated: true, completion: {})
}

override func viewDidDisappear(animated: Bool) {
    cancelSearch(self)
}

override func viewDidLoad() {
    super.viewDidLoad()

    searchController = UISearchController(searchResultsController: nil)
    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false
    searchController.delegate = self
    searchController.hidesNavigationBarDuringPresentation = false
    searchController.loadViewIfNeeded()  /* Fixes bug in iOS http://stackoverflow.com/questions/32675001/uisearchcontroller-warning-attempting-to-load-the-view-of-a-view-controller */
    definesPresentationContext = true
    tableView.sectionIndexBackgroundColor = UIColor.clearColor()
    tableView.sectionIndexTrackingBackgroundColor = UIColor.clearColor()
}
extension tvc: UISearchResultsUpdating {
// MARK: - UISearchResultsUpdating Delegate
func updateSearchResultsForSearchController(searchController: UISearchController) {
    filterContentForSearchText(searchController.searchBar.text!)
    }
}
func cancelSearch(sender: AnyObject?) {
if sender!.searchController.active == true {
sender?.searchController.resignFirstResponder()
sender!.navigationController!!.dismissViewControllerAnimated(false, completion: {})
sender!.searchController.searchBar.text = ""
sender!.searchController.active = false
    }
}

答案 1 :(得分:0)

我认为问题是你要么没有为imageViewSnapshot设置框架,要么设置错误的框架。由于imageViewSnapshot包含搜索栏,因此您必须设置框架,使其位于导航栏后面。或imageViewSnapshot应仅包含fromViewTransitionFromView的可见区域。

相关问题