【问题标题】: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
   }

【问题讨论】:

    标签: ios swift


    【解决方案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)
     }
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-27
      • 2021-08-09
      • 2021-03-15
      • 1970-01-01
      • 2020-06-25
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多