我只想在我的 iOS 应用程序的所有视图控制器中支持垂直方向。However, I embed a YouTube video in one of my view controllers, and when that video is selected to take up the full screen, I want the user to be able to orient his/her phone horizontally so the video expands to take the full screen .
编辑:我尝试在 iOS 6 中使用 Autorotate 中的以下代码有奇怪的行为:
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return self.fullScreenVideoIsPlaying ?
UIInterfaceOrientationMaskAllButUpsideDown :
UIInterfaceOrientationMaskPortrait;
}
在呈现UIWebView
/YouTube 框架的视图控制器中,我的代码中有以下代码viewDidLoad
:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(windowNowVisible:)
name:UIWindowDidBecomeVisibleNotification
object:self.view.window
];
- (void)windowNowVisible:(NSNotification *)notification
{
AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
appDelegate.fullScreenVideoIsPlaying = !(appDelegate.fullScreenVideoIsPlaying);
}
但是,当用户在全屏 YouTube 视频上按下完成时,如果他/她仍然将手机水平放置,那么呈现视图控制器也保持水平(我希望当前视图控制器是纵向的)。这是变量的竞赛,它的fullSreenVideoIsPlaying
更新速度不够快,因此我的呈现视图控制器是纵向的。
任何有关如何实现这一目标的反馈将不胜感激。
谢谢!