2014-10-31 65 views
0

我见过类似的问题已经问过,所以我错过了正确的答案。 我的应用程序必须始终处于肖像模式,除非它显示媒体播放器必须处于横向全屏模式。如何在横向模式下显示MPVideoPlayer和纵向显示所有其他视图?

下面是它如何做的:

AppDelegate.m

@implementation HCAAppDelegate 

+(void) landscapeLock { 
    HCAAppDelegate* appDelegate = [UIApplication sharedApplication].delegate; 
    appDelegate.screenIsLandscapeOnly= true; 
    appDelegate.screenIsPortraitOnly = false; 
} 

+(void) portraitLock 
{ 
    HCAAppDelegate* appDelegate = [UIApplication sharedApplication].delegate; 
    appDelegate.screenIsPortraitOnly = true; 
    appDelegate.screenIsLandscapeOnly = false; 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
... 
    [HCAAppDelegate portraitLock]; 
} 


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

媒体播放器创建为

-(void) _initPlayer 
{ 
    [HCAAppDelegate landscapeLock]; 

    _moviePlayer = [[HCAMoviePlayerController alloc]init]; 
    [_moviePlayer setControlStyle:MPMovieControlStyleDefault]; 

    _moviePlayer.shouldAutoplay = YES; 

    [self.view addSubview:_moviePlayer.view]; 
    [_moviePlayer setFullscreen:YES animated:YES]; 
} 

,并斥为

- (void) _finishPlay 
{ 
... 
    [_moviePlayer.view removeFromSuperview]; 
    [HCAAppDelegate portraitLock]; 
} 

当玩家被初始化它转到l风景,但是当它被解散时它仍然处于风景模式,为什么portraitLock方法不起作用? 谢谢!

回答

0

在深入了解这个问题之后,我明白了错误在哪里。将发布答案在这里关闭案例,并提供一个工作示例的主题。 将mediaPlayer视图添加到现有的视图控制器 [self.view addSubview:_moviePlayer.view]; 作品但删除后 [_moviePlayer.view removeFromSuperview]; 的portraitLock不影响self.view

的工作方式是创建一个新的控制器和现在/驳回:

这里是代码: 呈现全屏播放的看法。注意,高度/宽度被切换在 线_moviePlayer.view SETFRAME:

UIViewController *movieVC = (UIViewController*) [storyboard instantiateViewControllerWithIdentifier:@"MoviePlayer"]; 

movieVC.view = [[UIView alloc] initWithFrame:CGRectMake(0, 
                 0, 
                 [[UIScreen mainScreen] applicationFrame].size.width, 
                 [[UIScreen mainScreen] applicationFrame].size.height)]; 

[HCAAppDelegate landscapeLock]; 

[_moviePlayer.view setFrame:CGRectMake(0, 
             0, 
             movieVC.view.frame.size.height, 
             movieVC.view.frame.size.width)]; 

[movieVC.view addSubview:_moviePlayer.view]; 
[self.navigationController presentViewController:movieVC animated:YES completion:nil]; 

驳回视图:

[_moviePlayer stop]; 
[HCAAppDelegate portraitLock]; 
[self.navigationController dismissViewControllerAnimated:YES completion:nil]; 
相关问题