したがって、私のアプリにはMPMoviePlayerViewController
、ユーザーがビデオを表示できるようにする があります。どの向きでもビデオを見ることができ、MPMoviePlayerViewController
終了して「完了」を押すと、前のビュー コントローラーに戻りますが、縦向きのみです。問題は、[完了] ボタンを押すと、View Controller が縦向きに戻る前に横向きで短時間点滅することです。これは、実行時にどのように見えるかです: http://1drv.ms/1RSqUUD
私のコードが添付されています:
import UIKit
import MediaPlayer
class VideoViewController: UIViewController {
var movieViewController : MPMoviePlayerViewController?
var movieplayer : MPMoviePlayerController!
override func viewDidLoad() {
var url = NSURL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")!
movieViewController = MPMoviePlayerViewController(contentURL: url)
}
override func viewWillAppear(animated: Bool) {
let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
@IBAction func WatchPressed(sender: AnyObject)
{
self.presentMoviePlayerViewControllerAnimated(movieViewController)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "Rotated", name: UIDeviceOrientationDidChangeNotification, object: nil)
}
func Rotated()
{
if UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation)
{
if UIDevice.currentDevice().orientation.rawValue == 4 || UIDevice.currentDevice().orientation.rawValue == 3
{
movieViewController!.view.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)
}
}
else if UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation)
{
if UIDevice.currentDevice().orientation.rawValue == 1 || UIDevice.currentDevice().orientation.rawValue == 2
{
movieViewController!.view.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)
let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}
編集
このコードを使用する場合: (以下で提案されているように) http://txt.do/nt1s ユーザーが横向きに回転するとムービー プレーヤーから放り出され、縦向きに回転する前に横向きの前のビュー コントローラーが短時間表示されます。 .