[英]How can a UIView subclass get notified when it has been added as subview to another view?
I need some kind of hook or template method to override which gets called when a view is added as subview to another view, but couldn't find it in the documentation. 我需要某种挂钩或模板方法来覆盖在将视图作为子视图添加到另一个视图时调用的方法,但是在文档中找不到它。 It must be something that gets called automatically by UIKit.
它必须是UIKit自动调用的东西。 The reason is that my view must start some animations as soon as there is a superview, but stop animating as soon as there is no superview anymore.
原因是我的视图必须在有超级视图时立即开始一些动画,但在没有超级视图时立即停止动画。
I can't override -setSuperview: as Xcode is not indicating that such class exists - and I can't call super. 我不能覆盖-setSuperview:因为Xcode并不表明该类存在-我也不能调用super。
You want to override - (void)didMoveToSuperview
. 您要覆盖
- (void)didMoveToSuperview
。
didMoveToSuperview
Tells the view that its superview changed.
告诉视图其视图已更改。
The default implementation of this method does nothing.
此方法的默认实现不执行任何操作。 Subclasses can override it to perform additional actions whenever the superview changes.
每当父视图更改时,子类都可以覆盖它以执行其他操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.