gpt4 book ai didi

ios - UIView 即使在开始从 superview 中移除后也会重新出现

转载 作者:搜寻专家 更新时间:2023-11-01 06:33:21 25 4
gpt4 key购买 nike

我有一个问题,如果我从 super View 中删除 subview ,然后当我推送到另一个 VC 并返回时,所有删除的 subview 都会重新出现在 View 中,我已经尝试了所有方法并检查了我的代码,如果 viewDidApper 也是。

enter image description here

//HERE IS HOW I ADD VIEWS

func addusers() {

for user in 0...5 {
let radarButton = PRButton(frame: CGRect(x: 0, y: 0, width: itemSize.width, height: itemSize.height+14))
radarButton.profileButton?.setImage(UIImage(named: "dummy-avatar.png"), for: UIControlState())
radarButton.profileName.setTitle("test \(user)", for: .normal)

repeat {
let center = generateCenterPointInRadar()
radarButton.center = CGPoint(x: center.x, y: center.y)

} while (itemFrameIntersectsInOtherItem(radarButton.frame))
radarButton.profileButton?.addTarget(self, action: #selector(didTapUser), for: .touchUpInside)
radarButton.profileName?.addTarget(self, action: #selector(didTapUser), for: .touchUpInside)
self.addSubview(radarButton)
items.append(radarButton)
}

}

//HERE IS HOW I REMOVE VIEWS
func removeAllUsers() {
for view in self.subviews {
if view is PRButton {
view.removeFromSuperview()
}
}
items.removeAll()

}
//Remove from superview
override func removeFromSuperview() {

UIView.beginAnimations("", context: nil)
UIView.setAnimationDuration(1)
self.alpha = 0
UIView.setAnimationDidStop(Selector(("callSuperRemoveFromSuperview")))
UIView.commitAnimations()

}

fileprivate func callSuperRemoveFromSuperview() {
super.removeFromSuperview()
}

提前致谢

最佳答案

我看了测试项目。我想我发现了问题,它在 override func removeFromSuperview()我将其注释掉并编辑 removeAllUsers()

func removeAllUsers() {
for view in self.subviews {
if view is PRButton {
UIView.animate(withDuration: 1, animations: {
view.alpha = 0
}, completion: { (finished) in
view.removeFromSuperview()
})
}
}
items.removeAll()

}

现在,当我返回 viewController

时,我没有看到任何重复的用户

关于ios - UIView 即使在开始从 superview 中移除后也会重新出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44683205/

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