我在一個UIViewController上加入數個AVPlayerController.view
精簡後程式如下
let playerController = AVPlayerViewController()
self.view.addSubview(playerController.view)
碰到事件需要移除UIViewController上面所有剛剛加入的數個"playerController.view"
以下是我用來移除的程式
for item in self.view.subviews{
if item === AVPlayerViewController().view{
item.removeFromSuperview()
}
}
但是判斷式不管是上面那段還是
if item.isKindOfClass(AVPlayerViewController)
還是
if item.isMemberOfClass(AVPlayerViewController)
都找不到剛剛加入的playerController.view
就無法移除
查了很久試過很多方法還是不知道該怎麼移除playerController.view