UIView 似乎没有“didRemoveFromSuperview
”或“willRemoveFromSuperview
”之类的方法。那么,当 UIView 从其 superView 中删除时如何监听事件?我应该使用 KVO?提前致谢!
最佳答案
这有效(在 iOS8 上测试):
-(void) didMoveToWindow {
[super didMoveToWindow]; // (does nothing by default)
if (self.window == nil) {
// YOUR CODE FOR WHEN UIVIEW IS REMOVED
}
}
According to the UIView
docs :The default implementation of this method does nothing. Subclasses can override it to perform additional actions whenever the window changes.
The window property may be nil... This occurs when the receiver has just been removed from its superview or when the receiver has just been added to a superview that is not attached to a window.
关于ios - 当 UIView 与其 superView 分离时如何得到通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3074933/