简体   繁体   English

将UIView子类作为子视图添加到另一个视图时,如何获得通知?

[英]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.

相关问题 当SuperView UIScrollView滚动了UIView子类时,如何获得通知 - How can a UIView subclass get notified when it has been scrolled by its Superview UIScrollView 如何检测到已添加 UIView 子视图? - How can I detect that a UIView subview has been added? UIView - 如何在加载视图时收到通知? - UIView - How to get notified when the view is loaded? iphone UIView - 在加载视图时收到通知? - iphone UIView - Get notified when view has loaded? 从超级视图中删除TableView后,如何通知我? - How can I be notified when a TableView has been removed from the super view? 如何保存已添加NSUserDefaults的子视图? - How to save the subView that has been added with NSUserDefaults? 检测我的UIView子类何时被添加到另一个UIView - Detect when my UIView subclass is added to another UIView 在iOS应用中,即使没有添加主自定义UIView,我仍然可以将其他视图对象添加为子视图吗? - In an iOS app, even when no main custom UIView is added, I can still add other view objects as subview? 如何在代码中将uiview的自定义子类作为子视图添加到uiview的另一个自定义子类? - How to add a custom subclass of uiview as a subview to another custom subclass of uiview in code? 确定UIView子类的可见部分(框架),该部分作为子视图添加到表视图中的单元格 - Determining a visible part (frame) of UIView subclass, that is added as a subview to cell in table view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM