0

我在 swift 3 中使用cosmicmindMaterial Framework的 ToolbarController。我在这个控制器中有两个 UIView,一个在屏幕顶部,另一个在屏幕底部。底部 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
    }
 }
4

1 回答 1

0

问题是您正在viewDidLoad函数中进行框架计算,而这些计算没有考虑ToolbarController计算,因为在构建时ToolbarControllerRootViewController连接,它作为参数传入,这是在viewDidLoad调用方法之后。您可以使用LayoutAPIMaterial来动态计算视图的位置,例如更新后的代码如下所示:

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 示例项目

祝一切顺利 :)

于 2017-03-01T18:07:16.580 回答