gpt4 book ai didi

ios - UIView removeFromSuperview 正在调用 didMoveToSuperview

转载 作者:IT王子 更新时间:2023-10-29 05:41:26 25 4
gpt4 key购买 nike

我不明白为什么 UIView 的 removeFromSuperview 调用 didMoveToSuperview

我认为 didMoveToSuperview 仅在将 View 添加到 View 时调用。谁能解释为什么 removeFromSuperview 调用 didMoveToSuperview

这是我在 removeFromSuperview 中所做的:

public override func removeFromSuperview() {

clearDelegates()

chaosPad?.removeFromSuperview()
brushSliders?.removeFromSuperview()
moodSlider?.removeFromSuperview()
brushShapeMenu?.removeFromSuperview()
moodMenu?.removeFromSuperview()
gravityMenu?.removeFromSuperview()
rotationMenu?.removeFromSuperview()

menuGroups = []
centerButtons = []
scrollMenuItems = []
menu?.removeFromSuperview()
menu = nil

super.removeFromSuperview()
}

func clearDelegates() {
chaosPad?.delegate = nil
viewController = nil
}

这里是显示如何调用 didMoveToSuperview 的调用堆栈:

#0  0x0000000110f39708 in specialized _fatalErrorMessage(StaticString, StaticString, StaticString, UInt) -> () ()
#1 0x000000010b9cb960 in TDTOilistMenuPainting.configureFrames() -> () at /FastDev/TDTPhotoLib/Oilist/Classes/TDTOilistMenuPainting.swift:161
#2 0x000000010b9cb83e in TDTOilistMenuPainting.didMoveToSuperview() -> () at /FastDev/TDTPhotoLib/Oilist/Classes/TDTOilistMenuPainting.swift:146
#3 0x000000010b9cb872 in @objc TDTOilistMenuPainting.didMoveToSuperview() -> () ()
#4 0x000000010f5d1db5 in __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke ()
#5 0x000000010dc87c60 in -[NSISEngine withBehaviors:performModifications:] ()
#6 0x000000010f5d19b1 in -[UIView(Hierarchy) _postMovedFromSuperview:] ()
#7 0x000000010f5cf610 in __UIViewWasRemovedFromSuperview ()
#8 0x000000010f5cf107 in -[UIView(Hierarchy) removeFromSuperview] ()
#9 0x000000010b9c9aba in TDTOilistMenuPainting.removeFromSuperview() -> () at /FastDev/TDTPhotoLib/Oilist/Classes/TDTOilistMenuPainting.swift:73
#10 0x000000010ba6d269 in TDTPaintingViewController.(navigationController(UINavigationController, animationControllerForOperation : UINavigationControllerOperation, fromViewController : UIViewController, toViewController : UIViewController) -> UIViewControllerAnimatedTransitioning?).(closure #2) at /FastDev/TDTPhotoLib/Oilist/Classes/TDTPaintingViewController.swift:2706

最佳答案

这是正常行为。 didMoveToSuperview 会在 View 的父 View 发生更改时被调用,即使它更改为 nil。您可以在该方法中检查父 View 是否为 nil 以确定它是否已添加到其父 View 或从其父 View 中删除,例如:

override func didMoveToSuperview() {
if let superview = self.superview {
// the view was added as a subview to superview
}
else {
// the view was removed from its superview
}
}

关于ios - UIView removeFromSuperview 正在调用 didMoveToSuperview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40580759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com