【发布时间】:2015-10-07 10:31:03
【问题描述】:
我有 VideoViewController.swift,当我按下按钮时,我想像这张照片一样在 secondviewcontroller 中播放视频(不是全屏)
我尝试使用模态视图控制器,但它不起作用.. 有什么问题?
这是源代码: VideoViewController.swift
import UIKit
import AVKit
import AVFoundation
class VideoViewController: UIViewController {
@IBOutlet weak var AVPlayerView: UIView!
override func shouldAutorotate() -> Bool {
return false
}
override func viewDidLoad() {
super.viewDidLoad()
// yoon // from web
let sampleURL = NSURL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!
let player = AVPlayer(URL: sampleURL)
let playerLayer = AVPlayerLayer(player: player)
let videoWidth = 320
let videoHeigh = 180
let screenWidth = self.view.frame.size.width
let screenHeigh = self.view.frame.size.height
playerLayer.frame = CGRectMake(
(screenWidth/2 - CGFloat(videoWidth/2)),
(screenHeigh/2 - CGFloat(videoHeigh/2)),
CGFloat(videoWidth),
CGFloat(videoHeigh))
AVPlayerView.layer.addSublayer(playerLayer)
player.play()
//AVPlayerView.backgroundColor = UIColor.blackColor()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
视图控制器。快
import UIKit
import Social
import AVKit
import AVFoundation
class ViewController: UIViewController, SideBarDelegate {
@IBOutlet weak var AVPlayerView: UIView!
override func shouldAutorotate() -> Bool {
return false
}
@IBAction func videoStream(sender: AnyObject) {
self.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
// Cover Vertical is necessary for CurrentContext
self.modalPresentationStyle = .CurrentContext
// Display on top of current UIView
self.presentViewController(VideoViewController(), animated: true, completion: nil)
//self.preferredContentSize = CGSizeMake(320, 200)
}
【问题讨论】:
-
您似乎正在使用 xib 或故事板,如果您需要从故事板/xib 加载,则必须使用相应的分配而不是 VideoViewController()。
标签: ios swift modalviewcontroller