Ios 使用导航栏和iMessage应用程序

Ios 使用导航栏和iMessage应用程序,ios,autolayout,uinavigationbar,uisearchcontroller,imessage,Ios,Autolayout,Uinavigationbar,Uisearchcontroller,Imessage,我正在使用UISearchBar/UISearchController和MKMapView创建一个iMessage应用程序。搜索栏完美地显示在压缩视图中(我知道在压缩视图中不能有搜索栏,但只用于测试)固定在屏幕顶部。但是,在展开视图中,iMessage导航栏会隐藏搜索栏。我无法将搜索栏约束到顶部布局指南,因为导航控制器位于顶部布局指南的上方。有关如何将搜索栏限制在iMessage顶部导航栏下方的任何想法?编辑: 我还没有上过iOS10,也不知道iMessage应用程序。你的问题现在更有意义了。无

我正在使用UISearchBar/UISearchController和MKMapView创建一个iMessage应用程序。搜索栏完美地显示在压缩视图中(我知道在压缩视图中不能有搜索栏,但只用于测试)固定在屏幕顶部。但是,在展开视图中,iMessage导航栏会隐藏搜索栏。我无法将搜索栏约束到顶部布局指南,因为导航控制器位于顶部布局指南的上方。有关如何将搜索栏限制在iMessage顶部导航栏下方的任何想法?

编辑: 我还没有上过iOS10,也不知道iMessage应用程序。你的问题现在更有意义了。无论如何,我会把我的原始答案留在这里


这是一个拥有苹果原始iMessages应用程序基础知识的项目。当然还有很多需要改进的地方,但这应该会让你开始

显示带有消息的表视图,除非向上滚动以查找搜索栏,否则搜索栏最初是隐藏的。单击搜索栏后,导航栏将隐藏,搜索栏也会显示“取消”按钮

如果你想下载整个项目,这样你就可以看到我如何设置故事板,你可以在这里下载项目。

编辑: 我还没有上过iOS10,也不知道iMessage应用程序。你的问题现在更有意义了。无论如何,我会把我的原始答案留在这里


这是一个拥有苹果原始iMessages应用程序基础知识的项目。当然还有很多需要改进的地方,但这应该会让你开始

显示带有消息的表视图,除非向上滚动以查找搜索栏,否则搜索栏最初是隐藏的。单击搜索栏后,导航栏将隐藏,搜索栏也会显示“取消”按钮

如果你想下载整个项目,这样你就可以看到我如何设置故事板,你可以在这里下载项目。


我相信原来的问题是关于iOS 10中的新iMessage应用程序,而不是默认消息应用程序。现在这个问题更有意义。我相信原来的问题是关于iOS 10中的新iMessage应用程序,而不是默认消息应用程序。现在这个问题更有意义了。
import UIKit

class TableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

@IBOutlet weak var tableView: UITableView!
var messages = [Int]()

override func viewDidLoad() {
    super.viewDidLoad()

    for x in 0...25 {
        messages.append(x)
    }

    // Start with the tableview scrolled down by 44
    // so the search bar doesn't show up only until you scroll back up
    // Like in the iMessage App.
    let height = tableView.tableHeaderView?.frame.size.height
    let pointXY = CGPoint(x: 0, y: height!)
    tableView.setContentOffset(pointXY, animated: false)
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return messages.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! TableViewCell
    cell.messageLabel.text = "Message # \(indexPath.row)"

    return cell
}

}

extension TableViewController: UISearchBarDelegate {

func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
    // Hide the navigation bar when they press on search
    navigationController?.setNavigationBarHidden(true, animated: true)
    searchBar.setShowsCancelButton(true, animated: true)
}

func searchBarCancelButtonClicked(searchBar: UISearchBar) {
    navigationController?.setNavigationBarHidden(false, animated: true)
    searchBar.setShowsCancelButton(false, animated: false)
    searchBar.resignFirstResponder()

}

}