当 UIView 与其 superView 分离时如何收到通知?
看来UIView没有像“didRemoveFromSuperview
”或“willRemoveFromSuperview
”这样的方法。那么,当UIView从其superView中删除时如何监听事件?我应该使用科沃?提前致谢!
It seems that the UIView has not methods like "didRemoveFromSuperview
" or "willRemoveFromSuperview
".Then,How to listen to the event when a UIView removed from its superView?I should use KVO? thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这有效(在 iOS8 上测试):
根据
UIView
文档:This works (tested on iOS8):
According to the
UIView
docs:这个主题已经很老了,但是我找到了一种方法。由于谷歌搜索不够有用,所以这里是(取自 UIView 的文档)
This topic is quite old, but I found a way to do it .Since google search wasn't helpful enough, here it is (taken from UIView's docs)
您可以对 UIView 进行子类化,并通过其
- (void)removeFromSuperview
方法发布通知。You can subclass your UIView and post notifications from it's
- (void)removeFromSuperview
method.