<tfoot id='Z179l'></tfoot>
    • <bdo id='Z179l'></bdo><ul id='Z179l'></ul>

    1. <legend id='Z179l'><style id='Z179l'><dir id='Z179l'><q id='Z179l'></q></dir></style></legend>

    2. <i id='Z179l'><tr id='Z179l'><dt id='Z179l'><q id='Z179l'><span id='Z179l'><b id='Z179l'><form id='Z179l'><ins id='Z179l'></ins><ul id='Z179l'></ul><sub id='Z179l'></sub></form><legend id='Z179l'></legend><bdo id='Z179l'><pre id='Z179l'><center id='Z179l'></center></pre></bdo></b><th id='Z179l'></th></span></q></dt></tr></i><div id='Z179l'><tfoot id='Z179l'></tfoot><dl id='Z179l'><fieldset id='Z179l'></fieldset></dl></div>
    3. <small id='Z179l'></small><noframes id='Z179l'>

      1. 在容器视图中加载 ViewController

        时间:2023-09-11

            <small id='d0Z7a'></small><noframes id='d0Z7a'>

              <tbody id='d0Z7a'></tbody>

            <legend id='d0Z7a'><style id='d0Z7a'><dir id='d0Z7a'><q id='d0Z7a'></q></dir></style></legend>
            <i id='d0Z7a'><tr id='d0Z7a'><dt id='d0Z7a'><q id='d0Z7a'><span id='d0Z7a'><b id='d0Z7a'><form id='d0Z7a'><ins id='d0Z7a'></ins><ul id='d0Z7a'></ul><sub id='d0Z7a'></sub></form><legend id='d0Z7a'></legend><bdo id='d0Z7a'><pre id='d0Z7a'><center id='d0Z7a'></center></pre></bdo></b><th id='d0Z7a'></th></span></q></dt></tr></i><div id='d0Z7a'><tfoot id='d0Z7a'></tfoot><dl id='d0Z7a'><fieldset id='d0Z7a'></fieldset></dl></div>
                <bdo id='d0Z7a'></bdo><ul id='d0Z7a'></ul>

                  <tfoot id='d0Z7a'></tfoot>

                  本文介绍了在容器视图中加载 ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 VC 中有一个全屏的 containerView.如果我从 Storyboard 手动将子项添加到 containerView 中,则进行嵌入 segue 看起来很好:

                  I have a containerView with full screen inside a VC. If i add a child to the containerView manually from a Storyboard doing a embed segue looks fine:

                  但如果我通过代码嵌入 VC:

                  But if I embed the VC by code:

                  class BannerContainerVC: UIViewController {
                  
                      @IBOutlet weak var container: UIView!
                  
                      override func viewDidLoad() {
                          super.viewDidLoad()
                          let vc = storyboard?.instantiateViewControllerWithIdentifier("test") as UIViewController
                          self.container.addSubview(vc.view)
                      }
                  }
                  

                  我得到了超级奇怪的结果:

                  I get super strange results:

                  推荐答案

                  你需要告诉你的 BannerContainer 视图控制器它有一个新的子控制器,并告诉 Child 它有一个父 VC.Apple Docs 此处对此进行了描述.像这样:

                  You need to tell your BannerContainer view controller that it has a new child controller, and to tell the Child that it has a parent VC. This is described in the Apple Docs here. Like this:

                     [self addChildViewController:vc];
                     vc.view.frame = CGRectMake(0, 0, self.container.frame.size.width, self.container.frame.size.height);
                     [self.container addSubview:vc.view];
                     [vc didMoveToParentViewController:self];
                  

                  或者在 Swift 中:

                  Or in Swift:

                      self.addChildViewController(vc)
                      vc.view.frame = CGRectMake(0, 0, self.container.frame.size.width, self.container.frame.size.height);
                      self.container.addSubview(vc.view)
                      vc.didMoveToParentViewController(self)
                  

                  这样可以保证各种布局和触摸方法都传递给子VC;我怀疑您遇到的布局问题可能是由于当前未调用这些方法.

                  This ensures that various layout and touch methods are passed through to the child VC; I suspect the layout problems you have may be due to those methods not currently being called.

                  这篇关于在容器视图中加载 ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用自动布局、IB 和字体大小时表头视图高度错误 下一篇:在 UIScrollView 的底部查看,带有 AutoLayout

                  相关文章

                    <bdo id='mOi0q'></bdo><ul id='mOi0q'></ul>

                    <small id='mOi0q'></small><noframes id='mOi0q'>

                  1. <tfoot id='mOi0q'></tfoot>
                  2. <i id='mOi0q'><tr id='mOi0q'><dt id='mOi0q'><q id='mOi0q'><span id='mOi0q'><b id='mOi0q'><form id='mOi0q'><ins id='mOi0q'></ins><ul id='mOi0q'></ul><sub id='mOi0q'></sub></form><legend id='mOi0q'></legend><bdo id='mOi0q'><pre id='mOi0q'><center id='mOi0q'></center></pre></bdo></b><th id='mOi0q'></th></span></q></dt></tr></i><div id='mOi0q'><tfoot id='mOi0q'></tfoot><dl id='mOi0q'><fieldset id='mOi0q'></fieldset></dl></div>

                      <legend id='mOi0q'><style id='mOi0q'><dir id='mOi0q'><q id='mOi0q'></q></dir></style></legend>