2017-02-09 110 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 –