我正在開發一個應用程序,其中我在頂部有一個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的視圖...它沒有奏效。
謝謝!