好像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/