gpt4 book ai didi

swift - 如何删除我在播放 AVplayer Swift 时添加的图层

转载 作者:行者123 更新时间:2023-11-28 06:49:21 25 4
gpt4 key购买 nike

我有一个应用程序,它会多次重新进入相​​同的 View ,每次都会为 mp4 视频创建一个图层,因为这些图层没有被删除,或者至少这是我的猜测,所以会造成内存蠕变。我怎样才能删除添加的图层?

override func viewWillAppear(animated: Bool) {



let videoURL: NSURL = NSBundle.mainBundle().URLForResource("info2", withExtension: "mp4")!


mygtukas = AVPlayer(URL: videoURL)
mygtukas?.actionAtItemEnd = .None
mygtukas?.muted = true



let playerLayer = AVPlayerLayer(player: mygtukas)
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
playerLayer.zPosition = 1
playerLayer.frame = CGRect(x:20.0, y: 703.0, width: 36.0, height: 36.0)


view.layer.addSublayer(playerLayer)

mygtukas?.play()

NSNotificationCenter.defaultCenter().addObserver(self,
selector: "loopVideo",
name: AVPlayerItemDidPlayToEndTimeNotification,
object:nil)




}

最佳答案

这应该有效:

将 playerLayer 设为类实例并尝试以下操作。调用内部 loopVideo 方法:

playerLayer.removeFromSuperlayer()

关于swift - 如何删除我在播放 AVplayer Swift 时添加的图层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35364416/

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