2014-05-14 14 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]; 
}