代码之家  ›  专栏  ›  技术社区  ›  Rashed

将视图控制器添加为其他视图控制器中的子视图

  •  0
  • Rashed  · 技术社区  · 6 年前

    我已经读过了 LINK ,但不是为我工作。我想展示一个 viewController 视图控制器 .

    这是我的密码-

    import UIKit
    import CarbonKit
    
    class ViewController: UIViewController, CarbonTabSwipeNavigationDelegate {
    
     @IBOutlet weak var containerView: UIView!
    
     override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
    
            let items = ["All",  "WOMEN",  "MEN",  "KIDS",  "HOME",  "CITY"]
            let carbonTabSwipeNavigation = CarbonTabSwipeNavigation(items: items, delegate: self)
            carbonTabSwipeNavigation.insert(intoRootViewController: self)
        }
    
        func carbonTabSwipeNavigation(_ carbonTabSwipeNavigation: CarbonTabSwipeNavigation, viewControllerAt index: UInt) -> UIViewController {
    
            //           let screen = self.storyboard?.instantiateViewController(withIdentifier: "demo") as! demo
            //           showSubViewContrller(subViewController: vc)
            //           return screen
    
            let storyBoard = getStoryBoardByIndentifier(identifier: "All")
            let vc = storyBoard.instantiateViewController(withIdentifier: "AllViewController") as! AllViewController
            showSubViewContrller(subViewController: vc)
            return vc
        }
    
        //Subview Controller
        func showSubViewContrller(subViewController:UIViewController) {
            self.addChildViewController(subViewController)
            subViewController.view.frame = containerView.frame
            self.containerView.addSubview(subViewController.view)
            subViewController.didMove(toParentViewController: self)
        }
    
        func getStoryBoardByIndentifier(identifier:String)->UIStoryboard {
            return  UIStoryboard.init(name: identifier, bundle: nil)
        }
    
    }
    

    NavigationBar tapBar . 想展示一下 在一个 container .

    enter image description here

    但当视图加载时,它会掩盖/隐藏选项卡栏。

    enter image description here enter image description here

    如何解决这个问题并展示 视图控制器 项目链接- GitHub

    1 回复  |  直到 6 年前
        1
  •  2
  •   Paulw11    6 年前

    不知何故,我可以通过以下更改来解决您的问题:

    替换此方法 carbonTabSwipeNavigation.insert(intoRootViewController: self) 具有 carbonTabSwipeNavigation.insert(intoRootViewController: self, andTargetView: containerView) viewDidLoad

    UITaBar SuperView非安全区域的底部约束:

    enter image description here

    在ViewController中添加以下代码:

    override func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
    
            tabbar.invalidateIntrinsicContentSize()
        }
    

    UITabBar :

    enter image description here

    推荐文章