2017-02-09 153 views
0

我有一個帶有三個選項的標籤欄,當我嘗試轉到配置文件頁面時,底部的標籤欄被我編程添加的集合視圖所覆蓋。如何確定標籤欄不在此集合中?集合視圖覆蓋標籤欄

這裏是ProfilePageVC:

override func viewWillAppear(_ animated: Bool) { 
     super.viewWillAppear(true) 


     let flowLayout = UICollectionViewFlowLayout() 

     let collectionView = UICollectionView(frame: self.view.bounds, collectionViewLayout: flowLayout) 
     collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "collectionCell") 
     collectionView.delegate = self 
     collectionView.dataSource = self 
     collectionView.backgroundColor = UIColor.cyan 

     // self.lowerView.addSubview(collectionView) 
     self.lowerView.insertSubview(collectionView, belowSubview: self.view) 
     self.reloadInputViews() 

    } 

這裏就是我的標籤欄的代碼是(這是在剛剛常規默認VC)

class ViewController: UIViewController { 

    @IBOutlet weak var contentView: UIView! 

    var homeVC : UIViewController! 
    var testVC : UIViewController! 
    var profileVC : UIViewController! 

    var viewControllers : [UIViewController]! 

    //What tab we are pressing 
    var selectedVC : Int = 0 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     let storyboard = UIStoryboard(name: "Main", bundle: nil) 

     homeVC = storyboard.instantiateViewController(withIdentifier: "HomePage") 
     testVC = storyboard.instantiateViewController(withIdentifier: "RecordPage") 
     profileVC = storyboard.instantiateViewController(withIdentifier: "ProfilePage") 

     viewControllers = [homeVC, testVC, profileVC] 

     buttons[selectedVC].isSelected = true 
     hasPressedTab(buttons[selectedVC]) 
    } 

    @IBOutlet var buttons: [UIButton]! 

    @IBAction func hasPressedTab(_ sender: UIButton) { 

     let previousVC = selectedVC 
     selectedVC = sender.tag 
     buttons[previousVC].isSelected = false 

     let previousIndex = viewControllers[previousVC] 

     //removes from previous VC 
     previousIndex.willMove(toParentViewController: nil) 
     previousIndex.view.removeFromSuperview() 
     previousIndex.removeFromParentViewController() 

     //accesses current button selected 
     sender.isSelected = true 

     let vc = viewControllers[selectedVC] 
     addChildViewController(vc) 

     //addjusts size of VC to match the added contentView 
     vc.view.frame = contentView.bounds 
     contentView.addSubview(vc.view) 
     vc.didMove(toParentViewController: self) 
    } 

下面是說明問題的圖像:

棕褐色區域是較低視圖

帶出集合視圖作爲子視圖: https://ibb.co/gH2dWF

用的CollectionView作爲一個子視圖: https://ibb.co/jWh1ka

+0

爲什麼符文的服務器上後的iOS問題bruh – Jire

回答

0

我不知道什麼是「lowerView」是指,但你嘗試過添加子視圖的看法?

self.view.addSubview(collectionView) 
+0

是的,我有,那是目前在那裏,但它涵蓋了我的標籤欄,我已經在原來的帖子中包括兩張照片來解釋更多的情況 –

0

我相信問題可能是這一行:

self.lowerView.insertSubview(collectionView, belowSubview: self.view) 

爲什麼你想將其添加在lowerView?我實際上看不到在代碼中lowerView實際意味着什麼,但正常的流程是將collectionView作爲子視圖self.view添加。也許lowerView框架實際上在tabBar上,這就是它覆蓋標籤欄的原因。

的代碼將是:

self.view.addSubview(collectionView) 

如果需要集合視圖發送到後面,你可以把它:

self.view.sendSubview(toBack: collectionView) 
+0

不幸的是沒有工作。以下是顯示問題的兩張圖片。這裏是沒有在子視圖中的collectionview:https://ibb.co/jWh1ka https://ibb.co/gH2dWF,這裏是與子視圖中的collectionview https://ibb.co/jWh1ka –