BecomeFirstResponder使searchBar返回初始帧

时间:2015-09-05 13:12:17

标签: ios objective-c swift uisearchcontroller

我创建了一个视图,可以轻松点击导航栏顶部的按钮。然后我在这个视图中添加了一个searchController。然后我改变了searchBar的框架,使其适合视图。但是当searchBar becomeFirstResponder时,它会返回到初始帧?我怎么能避免这个?

viewDidLoad中

    searchController.delegate = self
    searchController.searchBar.delegate = self
    searchController.dimsBackgroundDuringPresentation = false
    searchController.hidesNavigationBarDuringPresentation = false
    searchController.searchBar.showsCancelButton = false
    searchController.searchBar.frame = CGRectMake(10, 8, self.view.frame.width - 20, 28)
    searchController.searchBar.searchBarStyle = UISearchBarStyle.Default
    searchController.searchBar.backgroundImage = UIImage()
    searchController.searchBar.backgroundColor = UIColor.clearColor()
    searchController.searchBar.barTintColor = UIColor.clearColor()
    //        searchController.searchBar.becomeFirstResponder()
    searchView.addSubview(searchController.searchBar)

点击搜索按钮

func searchButtonClicked(sender: UIBarButtonItem) {
    UIView.animateWithDuration(0.2, delay: 0.0, options:UIViewAnimationOptions.CurveLinear, animations: {

        self.searchView.frame = CGRectMake(0, 0, self.view.frame.width, self.navigationController!.navigationBar.frame.height)



        }, completion: {
            (value: Bool) in


    })
}

不是第一响应者

enter image description here

FirstResponder

enter image description here

0 个答案:

没有答案