在我的应用中,我正在使用MPMoviePlayerController
。我需要在横向和纵向方向上显示电影播放器。我只希望movie player
像这样显示,其他屏幕只应该是纵向的。我陷入困境,没有解决方案。从设置中我检查了三种模式,如下所示。
我正在使用ios 7和xcode 5.谢谢
答案 0 :(得分:0)
在包含MPMoviePlayerController的ViewController中,实现此功能(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
请注意:包含以上VC的ViewController应实现上述方法
答案 1 :(得分:0)
创建NavigationController的继承类
BaseNavigationController.h
@interface BaseNavigationController:UINavigationController
@end
BaseNavigationController.m
- (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])
{ if([[self.viewControllers lastObject] respondsToSelector:@ selector(shouldAutorotate)]) shouldAutorotateBool = [[self.viewControllers lastObject] shouldAutorotate]; }
return shouldAutorotateBool;
}
- (BOOL)isRotate { if([[self.viewControllers lastObject] isMemberOfClass:NSClassFromString(@“VideoVC”)]){
return YES;
}
return NO;
}
**特定的viewController使用以下代码进行方向**
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft;
}
- (BOOL)shouldAutorotate {
return YES;
}
答案 2 :(得分:0)
仅为MoviePlayer更改方向的最佳方法
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else
{
return UIInterfaceOrientationMaskPortrait;
}
}
答案 3 :(得分:0)
首先,如果要为iOS6制作应用程序,则应该使用UIViewController documentation中提供的iOS6方法。在iOS6中不推荐像shouldAutorotateToInterfaceOrientation
这样的方向方法,iOS6的替代方法是shouldAutoRotate
。如果您的应用也支持iOS5,则应该只使用旧方法。
第二个如果您在应用程序中使用UINavigationcontroller
并且需要具有不同的界面方向,那么navigationController可能会破坏应用程序中的界面方向。可能的解决方案(对我有用)是实现自定义UINavigationController
并覆盖该自定义UINavigationController
类中的界面方向方法,这将使您的viewControllers根据您设置的方向旋转,因为您的控制器被推送来自UINavigationController
。不要忘记在特定的viewController中添加这些方法。
<强> CustomNavigationController.h 强>
@interface CustomNavigationController : UINavigationController
@end
<强> CustomNavigationController.m 强>
@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];
}