Вид снизу не отображается в ToolbarController swift 3

Я использую ToolbarController из Material Framework от cosmicmind в swift 3. У меня есть два UIViews в этом контроллере, один вверху, а другой внизу экрана. Нижний UIView не отображается в контроллере. Я думаю, что это перемещается вниз по экрану.

Эта проблема возникает при тестировании с реальным устройством. В остальном симулятор показывает правильное поведение.

import UIKit
import Material

class RootViewController: UIViewController {
  open override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = Color.white
    prepareToolbar()
    handleTopView()
    handleBottomView()
  }

  func handleTopView() {
    let topView = UIView()
    topView.frame = CGRect(x: 0.00, y: 0.00, width: view.frame.size.width, height: 40.00)
    topView.backgroundColor = UIColor.gray
    view.addSubview(topView)
  }

  func handleBottomView() {
    let bottomView = UIView()
    bottomView.frame = CGRect(x: 0.00, y: self.view.frame.size.height, width: view.frame.size.width, height: 40.00)
    bottomView.backgroundColor = UIColor.blue
    view.addSubview(bottomView)
  }
}

extension RootViewController {
    fileprivate func prepareToolbar() {
      guard let toolbar = toolbarController?.toolbar else {
        return
      }

      toolbar.title = "Material"
      toolbar.titleLabel.textColor = .white
      toolbar.titleLabel.textAlignment = .left

      toolbar.detail = "Build Beautiful Software"
      toolbar.detailLabel.textColor = .white
      toolbar.detailLabel.textAlignment = .left
    }
 }

person Aamir Anwar    schedule 01.03.2017    source источник


Ответы (1)


Проблема в том, что вы выполняете расчеты кадров в функции viewDidLoad, и эти расчеты не учитывают расчеты ToolbarController, потому что в точке построения для ToolbarController RootViewController не подключен, он передается как параметр, который находится после viewDidLoad метод называется. Вы можете использовать Layout API в Material для динамического расчета позиции вашего представления, например, обновленный код будет выглядеть так:

import UIKit
import Material

class RootViewController: UIViewController {
    open override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = Color.white
        prepareToolbar()
        handleTopView()
        handleBottomView()
    }

    func handleTopView() {
        let topView = UIView()
        topView.backgroundColor = UIColor.gray
        view.layout(topView).top().horizontally().height(40)
    }

    func handleBottomView() {
        let bottomView = UIView()
        bottomView.backgroundColor = UIColor.blue
        view.layout(bottomView).bottom().horizontally().height(40)
    }
}

extension RootViewController {
    fileprivate func prepareToolbar() {
        guard let toolbar = toolbarController?.toolbar else {
            return
        }

        toolbar.title = "Material"
        toolbar.titleLabel.textColor = .white
        toolbar.titleLabel.textAlignment = .left

        toolbar.detail = "Build Beautiful Software"
        toolbar.detailLabel.textColor = .white
        toolbar.detailLabel.textAlignment = .left
    }
}

Я проверил, что это работает с последним примером проекта ToolbarController.

Всего наилучшего :)

person CosmicMind    schedule 01.03.2017
comment
Я пытаюсь уменьшить y на 40, но теперь это не работает. Я постепенно уменьшаю до 100. Теперь это отображается с этим кодом: bottomView.frame = CGRect(x: 0.00, y: self.view.frame.size.height - 100, width: view.frame.size.width, height: 40.00) - person Aamir Anwar; 02.03.2017
comment
Могу ли я увидеть, как вы инициализируете панель инструментов? - person CosmicMind; 03.03.2017
comment
Я использую последний образец проекта из пример проекта ToolbarController из GitHub. . Код полностью такой же, за исключением RootViewController, о котором я упоминал выше в своем вопросе. В этом я просто добавляю два представления. Один вверху, другой внизу. - person Aamir Anwar; 03.03.2017
comment
Я обновил свой ответ на ваш вопрос. Дайте мне знать, если это поможет. - person CosmicMind; 03.03.2017