我有一个只在Portrait中显示的应用程序。在此应用程序中是一个带有youtube嵌入视频的UIWebView。触摸后,此视频开始全屏播放。当这个全屏开始时,我想允许旋转。然而,当它结束时,我希望这回到只允许肖像。我已经尝试了以下结果:
在我的viewController的viewDidLoad中:
//Set listeners for video maximize
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("videoFull:"), name: "UIMoviePlayerControllerDidEnterFullscreenNotification", object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("videoMinimize:"), name: "UIMoviePlayerControllerWillExitFullscreenNotification", object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("videoFull:"), name: "MPMoviePlayerWillEnterFullscreenNotification", object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("videoMinimize:"), name: "MPMoviePlayerWillExitFullscreenNotification", object: nil)
在我的viewController中:
//Handles video full screen
func videoFull(notification:NSNotification){
(UIApplication.sharedApplication().delegate as WGMAppDelegate).videoFullscreen = true
}
//Handles video minimizes
func videoMinimize(notificaiton:NSNotification){
(UIApplication.sharedApplication().delegate as WGMAppDelegate).videoFullscreen = false
}
在我的app delegate中:
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> Int {
if(videoFullscreen){
return Int(UIInterfaceOrientationMask.All.rawValue)
}
else{
return Int(UIInterfaceOrientationMask.Portrait.rawValue)
}
}
除了我的通知代码永远不会被调用,因此将videoFullscreen变量保持为false。