我正在开发一个应用程序,其中我在顶部有一个NavigationBar,并将一个UIViewController添加为RootViewController。UIViewController隐藏在UINavigationController后面,但应放在
现在我的计划是添加一个新的子视图到这个UIViewController。新的Subview也扩展了UIViewController。我将控制器的de view(Gray Rect)添加到了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)
}}
我已经取消选中了“扩展边缘” - 在navigationcontroller的切换上的脚本。我也添加edgesForExtendedLayout = []到UIViewController和UIView它工作正常。但对于另一个UIViewController的视图...它没有奏效。
谢谢!