拦截didAddSubview [英] Intercepting didAddSubview

查看:189
本文介绍了拦截didAddSubview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这是一个简单的问题.我需要拦截didAddSubview,但是是否需要继承UIView的子类才能覆盖该方法?

I hope this is a simple question. I need to intercept didAddSubview, but will I need to subclass the UIView in order to override that method?

我要覆盖的UIViewUIViewControllerview属性,所以我只想知道如何使用它.

The UIView that I want to override is the UIViewController's view property, so I just want to know how to go about working with this.

谢谢!

推荐答案

从Apple

子类化UIView时,只有少数方法 应该覆盖,您可能会依赖的许多方法 您的需求.因为UIView是一个高度可配置的类,所以有 还有很多方法可以实现复杂的视图行为而无需 覆盖自定义方法,这些方法在替代方法"中进行了讨论 子类别部分. 同时,以下列表包括 您可能会考虑在UIView子类中覆盖的方法:

When subclassing UIView, there are only a handful of methods you should override and many methods that you might override depending on your needs. Because UIView is a highly configurable class, there are also many ways to implement sophisticated view behaviors without overriding custom methods, which are discussed in the Alternatives to Subclassing section. In the meantime, the following list includes the methods you might consider overriding in your UIView subclasses:

  • ...
  • didAddSubview:willRemoveSubview:-根据需要实施这些方法,以跟踪子视图的添加和删除.
  • ...
  • ...
  • didAddSubview:, willRemoveSubview: - Implement these methods as needed to track the additions and removals of subviews.
  • ...

因此,创建您的UIView子类并覆盖该方法.然后,对您的UIViewController说,它的view将是您的子类.要实现这一点,有两种方法:

So, create your UIView subclass and override the method. Then, say to your UIViewController that its view will be the one you have subclassed. To achieve this there are a couple of ways:

  • 通过Xib
  • 实施loadView方法并将view属性设置为您的自定义视图
  • 重新定义viewDidLoad
  • 中的view属性
  • by Xib
  • implementing loadView method and set the view property to be your custom view
  • redifining the view property in viewDidLoad

希望有帮助.

这篇关于拦截didAddSubview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆