iOS开发:视图生命周期

iOS应用的视图状态分为以下几种

  • 在viewcontroller的父类UIViewController中可以看到如下代码,通过重写不同的方法对操作视图渲染。
复制代码
@available(iOS 2.0, *)
public class UIViewController{
 
   public func viewDidLoad() // Called after the view has been loaded. For view controllers created in code, this is after -loadView. For view controllers unarchived from a nib, this is after the view is set.
   public func viewWillAppear(animated: Bool) // Called when the view is about to made visible. Default does nothing
    public func viewDidAppear(animated: Bool) // Called when the view has been fully transitioned onto the screen. Default does nothing
    public func viewWillDisappear(animated: Bool) // Called when the view is dismissed, covered or otherwise hidden. Default does nothing
    public func viewDidDisappear(animated: Bool) // Called after the view was dismissed, covered or otherwise hidden. Default does nothing
public func didReceiveMemoryWarning() // Called when the parent application receives a memory warning. On iOS 6.0 it will no longer clear the view by default.
 
}
复制代码
    • viewDidLoad():视图被加载到内存中时调用viewDidLoad方法,在该方法中可对视图上布局进行调整
    • viewWillAppear():视图可见前
    • viewDidAppear():视图已经可见,页面渲染完成后可以加载一些控件动画
    • viewWillDisappear():视图失去焦点前
    • viewWillDidDisappear():视图失去焦点后
    • didReceiveMemoryWarning():在iOS 6之后可使用此方法释放内存,包括视图控制器中的一些成员变量

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值