适用于youtube嵌入式视频的iOS 6.0自动旋转

我想只在我的iOS应用程序的所有视图控制器中支持垂直方向.但是,我在我的一个视图控制器中嵌入了一个YouTube视频,当选择该视频占据整个屏幕时,我希望用户能够水平定位他/她的手机,以便视频扩展为全屏.

编辑:我尝试使用Autorotate in iOS 6 has strange behaviour中的以下代码:

- (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变量的竞赛,它没有足够快地更新,因此我的呈现视图控制器是纵向的.

任何有关如何实现这一目标的反馈将不胜感激.

谢谢!

解决方法

通过将我在StackOverflow上找到的一些解决方案组合在一起来找出解决方案.

而不是使用此通知

[[NSNotificationCenter defaultCenter]
      addObserver:self
      selector:@selector(windowNowVisible:)
      name:UIWindowDidBecomeVisibleNotification
      object:self.view.window
 ];

我使用以下通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];

与实现

-(void) youTubeStarted:(NSNotification*) notif {
     AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
     appDelegate.fullScreenVideoIsPlaying = YES;
}
 -(void) youTubeFinished:(NSNotification*) notif {
     AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
     appDelegate.fullScreenVideoIsPlaying = NO;
 }

在我的AppDelegate中,我有

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
     NSUInteger orientations = UIInterfaceOrientationMaskPortrait;
     if (self.fullScreenVideoIsPlaying) {
         return UIInterfaceOrientationMaskAllButUpsideDown;
     }
     else {        
         if(self.window.rootViewController){
             UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
             orientations = [presentedViewController supportedInterfaceOrientations];
     }
return orientations;
 }

在我看来,控制器,我有

-(BOOL) shouldAutorotate {
     return NO;
 }
 -(NSUInteger)supportedInterfaceOrientations{
     return UIInterfaceOrientationMaskPortrait;
 }
 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
     return UIInterfaceOrientationPortrait;
 }

以上是来客网为你收集整理的适用于youtube嵌入式视频的iOS 6.0自动旋转全部内容,希望文章能够帮你解决适用于youtube嵌入式视频的iOS 6.0自动旋转所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。