【发布时间】:2018-04-02 01:49:57
【问题描述】:
我正在开发一个顶部有 NavigationBar 并添加 UIViewController 作为 RootViewController 的应用程序。
现在我的计划是向这个 UIViewController 添加一个新的 Subview。新的子视图也扩展了 UIViewController。我将控制器的视图(灰色矩形)添加到 UIViewController,但它位于 NavigationBar 后面。我不想要那个..所以我搜索了一个解决方案并发现了一些有趣的东西..: 当我只是将 UIView()(绿色矩形)添加到 UIViewController 时,视图的放置效果很好,因为我希望从另一个 UIViewController-View 中看到它。 我的代码如下所示:
class DashboardController: UIViewController {
var ccview:ContactCircleController!
override func viewDidLoad() {
super.viewDidLoad()
edgesForExtendedLayout = []
self.view.backgroundColor = .white
let test = UIView()
test.backgroundColor = .green
test.frame = CGRect(x: self.view.frame.width - 200, y: 0, width: self.view.frame.width / 2, height: self.view.frame.width / 2)
self.view.addSubview(test)
setup()
}
func setup(){
ccview = ContactCircleController()
ccview.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width / 2, height: self.view.frame.width / 2)
ccview.edgesForExtendedLayout = UIRectEdge.top
self.view.addSubview(ccview.view)
}}
我已经取消选中“扩展边缘” - 故事板上导航控制器的切换。我还向 UIViewController 添加了 edgesForExtendedLayout = [] ,对于 UIView 它工作正常。但是对于另一个 UIViewController 的视图......它没有用。
谢谢!
【问题讨论】:
标签: ios swift uiview view uinavigationcontroller