模态视图导航栏未正确显示
Posted
技术标签:
【中文标题】模态视图导航栏未正确显示【英文标题】:Modal View navigation bar not presenting properly 【发布时间】:2017-01-25 22:37:49 【问题描述】:我有一个简单的应用程序,我在其中运行一些 GET 查询并在它们完成后触发模式视图。呈现视图控制器包含一个带有搜索控制器/搜索栏的地图视图。当模态被触发时,它会按预期呈现 overCurrentContext(带有模糊效果),但是导航栏(带有取消按钮)会在搜索栏下方滑动。我可以看到导航栏已正确创建(带有标题和取消按钮),但它在搜索栏下方转换。我做错了什么吗?
呈现视图控制器
func showPopOver()
let fares = Fares(userLocation: userLocation, destination: userDestination)
fares.getFares _ in
self.RideCosts = self.storyboard!.instantiateViewController(withIdentifier: "RideCosts") as! RideCosts
self.RideCosts.modalPresentationStyle = .overCurrentContext
self.RideCosts.loadFares(fares: fares.fareArray)
self.present(self.RideCosts, animated: true, completion: nil)
modalViewController (RideCosts)
class RideCosts: UIViewController, UITableViewDelegate, UITableViewDataSource
@IBOutlet weak var tableView: UITableView!
@IBAction func cancel(_ sender: UIBarButtonItem)
dismiss(animated: true, completion: nil)
var fareArray: [(name: String, value: String)] = []
var arrayOfCellData = [cellData]()
override func viewDidLoad()
super.viewDidLoad()
let blurEffect = UIBlurEffect(style: .extraLight)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.frame
self.view.insertSubview(blurEffectView, at: 0)
self.view.backgroundColor = UIColor.clear
self.modalTransitionStyle = .crossDissolve
self.isModalInPopover = true
tableView.delegate = self
tableView.dataSource = self
【问题讨论】:
【参考方案1】:回到这个... Swift 新手错误,我通过将 modalpresentationStyle 设置为 overFullScreen 而不是 overCurrentContext 解决了模态演示(模态视图的导航栏显示在搜索栏下方)的问题
工作代码
func showPopOver()
let fares = Fares(userLocation: userLocation, destination: userDestination)
fares.getFares _ in
self.RideCosts = self.storyboard!.instantiateViewController(withIdentifier: "RideCosts") as! RideCosts
self.RideCosts.modalPresentationStyle = .overCurrentContext //FIX
self.RideCosts.loadFares(fares: fares.fareArray)
self.present(self.RideCosts, animated: true, completion: nil)
【讨论】:
以上是关于模态视图导航栏未正确显示的主要内容,如果未能解决你的问题,请参考以下文章