Use iOS 11 design language

This commit is contained in:
Bob Sun 2017-10-07 00:24:30 -07:00
parent d5353ba4d1
commit c57ae4f88e
2 changed files with 30 additions and 12 deletions

View file

@ -776,8 +776,8 @@
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="ZmJ-0Z-N04" sceneMemberID="viewController"> <navigationController automaticallyAdjustsScrollViewInsets="NO" id="ZmJ-0Z-N04" sceneMemberID="viewController">
<tabBarItem key="tabBarItem" title="Settings" image="Settings" selectedImage="Settings" id="6Xa-be-Z8g"/> <tabBarItem key="tabBarItem" title="Settings" image="Settings" selectedImage="Settings" id="6Xa-be-Z8g"/>
<toolbarItems/> <toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="wWs-15-HDi"> <navigationBar key="navigationBar" contentMode="scaleToFill" largeTitles="YES" id="wWs-15-HDi">
<rect key="frame" x="0.0" y="20" width="414" height="44"/> <rect key="frame" x="0.0" y="20" width="414" height="96"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
</navigationBar> </navigationBar>
<nil name="viewControllers"/> <nil name="viewControllers"/>

View file

@ -39,7 +39,6 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
uiSearchController.searchResultsUpdater = self uiSearchController.searchResultsUpdater = self
uiSearchController.dimsBackgroundDuringPresentation = false uiSearchController.dimsBackgroundDuringPresentation = false
uiSearchController.searchBar.isTranslucent = false uiSearchController.searchBar.isTranslucent = false
uiSearchController.searchBar.backgroundColor = UIColor.gray
uiSearchController.searchBar.sizeToFit() uiSearchController.searchBar.sizeToFit()
return uiSearchController return uiSearchController
}() }()
@ -48,10 +47,13 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
syncControl.addTarget(self, action: #selector(handleRefresh(_:)), for: UIControlEvents.valueChanged) syncControl.addTarget(self, action: #selector(handleRefresh(_:)), for: UIControlEvents.valueChanged)
return syncControl return syncControl
}() }()
private lazy var searchBarView: UIView = { private lazy var searchBarView: UIView? = {
let uiView = UIView(frame: CGRect(x: 0, y: 64, width: self.view.bounds.width, height: 56)) guard #available(iOS 11, *) else {
uiView.addSubview(self.searchController.searchBar) let uiView = UIView(frame: CGRect(x: 0, y: 64, width: self.view.bounds.width, height: 56))
return uiView uiView.addSubview(self.searchController.searchBar)
return uiView
}
return nil
}() }()
private lazy var backUIBarButtonItem: UIBarButtonItem = { private lazy var backUIBarButtonItem: UIBarButtonItem = {
let backUIBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(self.backAction(_:))) let backUIBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(self.backAction(_:)))
@ -188,18 +190,28 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
} else { } else {
searchController.searchBar.scopeButtonTitles = nil searchController.searchBar.scopeButtonTitles = nil
} }
if #available(iOS 11.0, *) {
navigationItem.hidesSearchBarWhenScrolling = true
}
} }
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
tabBarController!.delegate = self tabBarController!.delegate = self
searchController.searchBar.delegate = self searchController.searchBar.delegate = self
tableView.delegate = self tableView.delegate = self
tableView.dataSource = self tableView.dataSource = self
tableView.contentInset = UIEdgeInsetsMake(56, 0, 0, 0)
definesPresentationContext = true definesPresentationContext = true
view.addSubview(searchBarView) if #available(iOS 11.0, *) {
navigationItem.searchController = searchController
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.largeTitleDisplayMode = .automatic
navigationItem.hidesSearchBarWhenScrolling = true
} else {
// Fallback on earlier versions
tableView.contentInset = UIEdgeInsetsMake(56, 0, 0, 0)
view.addSubview(searchBarView!)
}
tableView.refreshControl = syncControl tableView.refreshControl = syncControl
SVProgressHUD.setDefaultMaskType(.black) SVProgressHUD.setDefaultMaskType(.black)
tableView.register(UINib(nibName: "PasswordWithFolderTableViewCell", bundle: nil), forCellReuseIdentifier: "passwordWithFolderTableViewCell") tableView.register(UINib(nibName: "PasswordWithFolderTableViewCell", bundle: nil), forCellReuseIdentifier: "passwordWithFolderTableViewCell")
@ -219,12 +231,18 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
if let path = tableView.indexPathForSelectedRow { if let path = tableView.indexPathForSelectedRow {
tableView.deselectRow(at: path, animated: false) tableView.deselectRow(at: path, animated: false)
} }
if #available(iOS 11.0, *) {
navigationItem.hidesSearchBarWhenScrolling = false
}
} }
override func viewWillLayoutSubviews() { override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews() super.viewWillLayoutSubviews()
searchBarView.frame = CGRect(x: 0, y: navigationController!.navigationBar.bounds.size.height + UIApplication.shared.statusBarFrame.height, width: UIScreen.main.bounds.width, height: 56) guard #available(iOS 11, *) else {
searchController.searchBar.sizeToFit() searchBarView?.frame = CGRect(x: 0, y: navigationController!.navigationBar.bounds.size.height + UIApplication.shared.statusBarFrame.height, width: UIScreen.main.bounds.width, height: 56)
searchController.searchBar.sizeToFit()
return
}
} }
func numberOfSections(in tableView: UITableView) -> Int { func numberOfSections(in tableView: UITableView) -> Int {