2014-05-14 63 views
0

在我的應用程序中,我使用的是MPMoviePlayerController。我需要以橫向和縱向方向顯示電影播放器​​。我只想要movie player就像這樣顯示,其他屏幕只應該是以肖像爲導向的。我被卡住了,沒有得到解決辦法。從設置我檢查了三種模式,如下所示。風景和肖像方向只在一個視圖控制器中

My Project settings

我使用的是iOS 7和Xcode的5感謝

+0

檢查我的答案上[計算器]另一篇文章(http://stackoverflow.com/questions/23491426/ios-7-how-to-allow-only-portrait-orientation-for-vc/23491583#23491583)我已經用了很多次,它適用於我。希望它能幫助你。 – Bharat

回答

0

在您的視圖控制器包含的MPMoviePlayerController,實現這個(iOS6的以上):

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskAll; //allow rotate landscape, portrait 
} 

在其他viewControllers:

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown; // portrait only 
} 

對於iOS版本較低比6,實現此方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
- (BOOL)shouldAutorotate 

需要注意的是:視圖控制器是包含上述風險投資應實現上述方法

0

創建繼承類NavigationController的

BaseNavigationController.h

進口

@interface BaseNavigationController:UINavi gationController

@end

BaseNavigationController.m

編譯mark-取向改變處理

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
BOOL shouldAutorotateBool = NO;

if ([self isRotate]) 
    { 
    if([[self.viewControllers lastObject] respondsToSelector:@selector(shouldAutorotate)]) 
     shouldAutorotateBool = [[self.viewControllers lastObject] shouldAutorotate]; 
} 
return shouldAutorotateBool; 

}

// iOS6的/ 7支持 - (NSUInteger)supportedInterfaceOrientations {

NSUInteger interfaceOrientation = UIInterfaceOrientationMaskPortrait; 

if ([self isRotate]) { 
    if([[self.viewControllers lastObject] respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)]) { 
     interfaceOrientation = [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
    } 
} 
return interfaceOrientation; 

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

UIInterfaceOrientation interfaceOrientation = UIInterfaceOrientationPortrait; 

if ([self isRotate]) { 
    if([[self.viewControllers lastObject] respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)]) { 
     interfaceOrientation = [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
    } 
} 
return interfaceOrientation; 

}

- (BOOL)shouldAutorotate {

BOOL shouldAutorotateBool = NO; 
if ([self isRotate]) 

{ 如果([[self.viewControllers lastObject] respondsToSelector:@selector(shouldAutorotate)]) shouldAutorotateBool = [[自我。viewControllers lastObject] shouldAutorotate]; }

return shouldAutorotateBool; 

}

- (BOOL)isRotate { 如果([[self.viewControllers lastObject] isMemberOfClass:NSClassFromString(@ 「VideoVC」)]){

return YES; 

} 
return NO; 

}

**而特定的viewController使用以下代碼定位**

編譯mark-用於裝置定向處理方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

return YES; 

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

return UIInterfaceOrientationLandscapeLeft; 

}

- (NSUInteger)supportedInterfaceOrientations {

return UIInterfaceOrientationMaskLandscapeLeft; 

}

- (BOOL)shouldAutorotate {

return YES; 

}

1

改變定向的最佳方式只有通貨膨脹的MoviePlayer

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]]) 
    { 
     return UIInterfaceOrientationMaskAllButUpsideDown; 
    } 
    else 
    { 
     return UIInterfaceOrientationMaskPortrait; 
    } 
} 
0

首先,你應該使用方法爲iOS6的在UIViewController documentation介紹,如果你正在你的應用程序爲iOS6的。 Orientation方法(如shouldAutorotateToInterfaceOrientation)已在iOS6中棄用,iOS6的替代方法爲shouldAutoRotate。如果您的應用也支持iOS5,則只應使用舊方法。

第二如果您在應用程序中使用UINavigationcontroller,並且您需要具有不同的接口方向,那麼navigationController可能會弄亂應用程序中的接口方向。可能的解決方案(爲我工作)是實現自定義UINavigationController並覆蓋該自定義UINavigationController類中的界面方向方法,這將使您的viewControllers根據您設置的方向旋轉,因爲您的控制器是從UINavigationController推送的。不要忘記在你的特定viewController中添加這些方法。

CustomNavigationController.h

@interface CustomNavigationController : UINavigationController 
@end 

CustomNavigationController。米

@implementation CustomNavigationController 

//overriding shouldRotate method for working in navController 
-(BOOL)shouldAutorotate 
{ 
    return [self.topViewController shouldAutorotate]; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return [self.topViewController supportedInterfaceOrientations]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [self.topViewController preferredInterfaceOrientationForPresentation]; 
} 
相關問題