2017-03-01 51 views
0

我使用的是Material FrameworkMaterial Framework由cosmicmind在swift 3中。我在这个控制器中有两个UIViews,其中一个在顶部,另一个在屏幕底部。底部UIView不显示在控制器中。我认为它会在屏幕之外向下移动。底部视图不显示在ToolbarController swift 3

在使用真实设备进行测试时出现此问题。其他模拟器显示正确的行为。

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 
    } 
} 

回答

0

的问题是,你正在做的框计算在viewDidLoad功能,这些计算不考虑,因为在施工为ToolbarControllerRootViewController点的ToolbarController计算未连接,它是通​​过在一个参数,这是在调用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 sample project

所有最好:)

+0

我试图用40减少y原点,但现在不工作。我逐渐减少到100.现在它显示这个代码: 'bottomView.frame = CGRect(x:0.00,y:self.view.frame.size.height - 100,width:view.frame.size.width,身高:40.00)' –

+0

我可以看到你是如何初始化工具栏的吗? – CosmicMind

+0

我正在使用来自GitHub的[ToolbarController示例项目](https://github.com/CosmicMind/Samples/tree/master/Projects/Programmatic/ToolbarController)的最新示例项目。除了在我的问题中提到的RootViewController之外,代码完全相同。在这里我只是添加两个视图。一个在顶部,另一个在底部。 –