ViewController启动加载过程

 ViewController加载过程(ShowViewCycle是ViewController.view的subView):

1. -[ViewController initWithNibName:bundle:] [Line 82] nibNameOrNil:(null), nibBundleOrNil:(null)

  ViewController初始化方法

    参数nibBundleOrNil:指定nib文件搜索的bundle,默认位mainBundle

    参数nibNameOrNil:指定nib文件的名称,如果不指定,则先搜索View.nib,再搜索 ViewController.nib

2. -[ViewController loadView] [Line 100] 

  在self.view==nil的条件下调用 

  2.1 -[ViewController willMoveToParentViewController:] [Line 363] 

  2.2 -[ShowViewCycle initWithFrame:] [Line 49] 

  2.3 -[ShowViewCycle setNeedsDisplay] [Line 259] 

    ShowViewCycle的属性改变都会触发setNeedsDisplay

  2.4 -[ShowViewCycle setNeedsDisplay] [Line 259] 

  2.5 -[ShowViewCycle setNeedsDisplay] [Line 259] 

  2.6 -[ShowViewCycle willMoveToSuperview:] [Line 174] 

  2.7 -[ShowViewCycle didMoveToSuperview] [Line 181] 

  2.8 -[ShowViewCycle setTranslatesAutoresizingMaskIntoConstraints:] 

    mas_makeConstraints主动触发

  2.9 -[ShowViewCycle isDescendantOfView:] [Line 200]

    addConstraint,会触发该判定,判定一个view是否是另一个view的subview

  2.10-[ShowViewCycle isDescendantOfView:] [Line 200] 

  2.11-[ShowViewCycle isDescendantOfView:] [Line 200] 

  2.12-[ShowViewCycle isDescendantOfView:] [Line 200] 

3. -[ViewController viewDidLoad] [Line 107] 

  3.1 -[ViewController shouldAutomaticallyForwardAppearanceMethods] [Line 336] 

  返回值如果是NO,子类必须重写- viewWillAppear: -viewDidAppear: -viewWillDisappear: -viewDidDisappear: -willRotateToInterfaceOrientation:duration:  -willAnimateRotationToInterfaceOrientation:duration: -didRotateFromInterfaceOrientation:方法

4. -[ViewController viewWillAppear:] [Line 159] 

  4.1 -[ViewController beginAppearanceTransition:animated:] [Line 298] 

  4.2 -[ViewController shouldAutomaticallyForwardAppearanceMethods] [Line 336] 

  4.3 -[ShowViewCycle willMoveToWindow:] [Line 188] 

  4.4 -[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.5 -[ShowViewCycle needsUpdateConstraints] [Line 375] 

  4.6 -[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.7 -[ShowViewCycle isDescendantOfView:] 

  4.8 -[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.9 -[ShowViewCycle isDescendantOfView:] [Line 200] 

  4.10-[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.11-[ShowViewCycle isDescendantOfView:] [Line 200] 

  4.12-[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.13-[ShowViewCycle isDescendantOfView:] [Line 200] 

  4.14-[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.15-[ShowViewCycle didMoveToWindow] [Line 195] 

  4.16-[ViewController viewWillLayoutSubviews] [Line 188] 

  4.17-[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.18-[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.19-[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.20-[ShowViewCycle intrinsicContentSize] [Line 451] 

      内在内容的大小

  4.21-[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.22-[ShowViewCycle updateConstraints] [Line 370]   

  4.23-[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.24-[ShowViewCycle alignmentRectInsets] [Line 434] 

  4.25-[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.26-[ShowViewCycle alignmentRectInsets] [Line 434]   

  4.27-[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.28-[ShowViewCycle alignmentRectInsets] [Line 434] 

  4.29-[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393]   

  4.30-[ShowViewCycle alignmentRectInsets] [Line 434] 

  4.31-[ViewController updateViewConstraints] [Line 387] 

  4.32-[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  4.33-[ShowViewCycle alignmentRectInsets] [Line 434] 

  4.34-[ViewController viewDidLayoutSubviews] [Line 196] 

  4.35-[ShowViewCycle layoutSubviews] [Line 231] 

  4.36-[ShowViewCycle drawRect:] [Line 252] 

  4.37-[ViewController shouldAutomaticallyForwardAppearanceMethods] [Line 336] 

5. -[ViewController viewDidAppear:] [Line 166] 

  5.1 -[ViewController didMoveToParentViewController:] [Line 370] 

  5.2 -[ViewController viewWillLayoutSubviews] [Line 188] 

  5.3 -[ViewController updateViewConstraints] [Line 387] 

  5.4 -[ShowViewCycle translatesAutoresizingMaskIntoConstraints] [Line 393] 

  5.5 -[ShowViewCycle alignmentRectInsets] [Line 434] 

  5.6 -[ViewController viewDidLayoutSubviews] [Line 196] 

转载于:https://www.cnblogs.com/StarMud/p/4597215.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ViewController中添加子ViewController可以使用以下步骤: 1.创建子ViewController 首先,需要创建一个子ViewController,可以使用以下代码: ``` let childViewController = ChildViewController() ``` 其中ChildViewController是你要添加的子ViewController类。 2.将子ViewController添加为子视图控制器 在将子ViewController添加到父ViewController之前,需要将其添加为父ViewController的子视图控制器。可以使用以下代码将子ViewController添加到父视图控制器中: ``` addChild(childViewController) ``` 注意,这里的addChild方法不仅将子ViewController添加为子视图控制器,还会将子ViewController的视图添加为父ViewController的视图层次结构中。 3.将子ViewController的视图添加到父ViewController中 现在,可以将子ViewController的视图添加到父ViewController中,可以使用以下代码: ``` view.addSubview(childViewController.view) ``` 这里,我们将子ViewController的视图添加到父ViewController的view中。 4.完成添加 最后,需要调用以下代码来完成添加: ``` childViewController.didMove(toParent: self) ``` 这里,我们调用了childViewController的didMove(toParent:)方法,通知子ViewController已经添加到了父ViewController中。 完整的代码如下所示: ``` let childViewController = ChildViewController() addChild(childViewController) view.addSubview(childViewController.view) childViewController.didMove(toParent: self) ``` 需要注意的是,在移除子ViewController时,需要按照相反的顺序执行上述步骤,并在最后调用以下方法来从父视图控制器中删除子视图控制器: ``` childViewController.removeFromParent() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值