我基本上有一个菜单,其中显示了一组按钮,每次点击其中一个按钮导致相同的视图显示不同,具体取决于从菜单中选择的项目,还有一个mp4播放。每当我进入其中一个项目(不同视图)或返回菜单时,我的记忆力会增加而且永远不会下降,视图会以模态呈现,如果这有任何区别的话。我猜测蠕变是由mp4引起的,我怎么能解决这个问题?
import Foundation
import UIKit
import AVKit
import AVFoundation
class menu : UIViewController {
var info : AVPlayer?
var count = 0
@IBAction func instrumentas2(sender: UIButton) {
count = 2
}
@IBAction func instrumentas1(sender: UIButton) {
count = 1
}
@IBAction func instrumentas0(sender: UIButton) {
count = 0 }
override func viewWillAppear(animated: Bool) {
let videoURL: NSURL = NSBundle.mainBundle().URLForResource("info2", withExtension: "mp4")!
info = AVPlayer(URL: videoURL)
info?.actionAtItemEnd = .None
info?.muted = true
let playerLayer = AVPlayerLayer(player: info)
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)
info?.play()
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "loopVideo",
name: AVPlayerItemDidPlayToEndTimeNotification,
object:nil)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
NSNotificationCenter.defaultCenter().removeObserver(self, name:AVPlayerItemDidPlayToEndTimeNotification, object: nil)
let du:display = segue.destinationViewController as! display
du.skaicius = count
}
func loopVideo() {
info?.seekToTime(kCMTimeZero)
info?.play()
}
}
我发布了整件事,因为我真的不确定是什么原因导致的。
答案 0 :(得分:0)
这行代码:
view.layer.addSublayer(playerLayer)
正在添加子图层。你有没有删除它们?