import AVFoundation
import UIKit
import AVKit
class Class1: UIViewController {
var playerViewController = AVPlayerViewController()
var playerView = AVPlayer()
var playerTimer = NSTimer()
override func viewDidAppear(animated:Bool) {
let fileURL = NSURL(fileURLWithPath: "file.mp4")
playerView = AVPlayer(URL: fileURL)
playerViewController.player = playerView
self.presentViewController(playerViewController, animated: true){
self.playerViewController.player?.play()
self.playerTimer = NSTimer.scheduledTimerWithTimeInterval(4.0, target: self, selector:Selector("stopAfter4seconds:"), userInfo: nil, repeats: false)
}
}
func stopAfter4seconds(timer: NSTimer){
self.playerViewController.player?.pause()
self.playerViewController.player = nil
self.presentingViewController?.dismissViewControllerAnimated(false, completion: nil)
self.presentViewController(GameViewController1(), animated: false, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
我的问题是,当我提出这一行:
self.presentViewController(GameViewController1(), animated: false, completion: nil)
我收到错误“尝试呈现GameViewController1 ......其视图不在窗口层次结构中!”
我确保在viewDidAppear中将其添加到视图层次结构中,但它似乎没有这样做
[更新]好了我现在意识到我正在呈现avplayerviewcontroller然后尝试播放下一个视图控制器。我如何“解雇”AVplayerviewcontroller以及我在右窗口层次结构中的下一个视图???
答案 0 :(得分:0)
playerViewController.presentViewController(GameViewController1(),
animated: false, completion: nil)