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方法不起作用? 謝謝!