我有一個問題,如果我從超級視圖中刪除子視圖,然後當我推到另一個VC和回來所有刪除的子視圖重新出現在視圖中我已經試過一切,並檢查我的代碼如果viewDidApper也是。UIView甚至在開始從超級視圖中刪除後重新出現
//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()
}
在此先感謝
您確定視圖不在另一個視圖容器內嗎? – Edu
@Edu我相信我已經包含了一個測試項目,您可以下載並檢查 –