天天看點

swift判斷View是否存在指定視圖

判斷A視圖是否存在于B視圖中,存在移除

var A = new View()
var B = new View()
//将 A添加到B中
A.tag = 999 //設定辨別
B.addSubview(A)

/*******判斷A是否存在B中********/
if (B.viewWithTag(999) != nil){
         A.removeFromSuperview() //将A視圖從父視圖中移除
    }
           

移除A視圖下所有的view

func removeFromSuperViewFunc(){
        let chilrenviews = A.subviews
        for ch in chilrenviews{
            ch.removeFromSuperview()
        }
    }
           
iOS