iOS 7界面方向 [英] iOS 7 Interface Orientation

查看:98
本文介绍了iOS 7界面方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序始终以纵向模式显示。

I have an app that is always showed in portrait mode.

但在某个地方,我有一个必须支持横向的媒体库。

But in somewhere i have a media gallery that must support landscape.

项目默认支持的方向是纵向。因此,图库仅以纵向模式显示。

The supported orientation by default in the project is portrait. Because of that the gallery is only showed in portrait mode.

如果我将项目设置更改为以纵向和横向显示,则图库工作正常,但我无法控制其他viewControllers只能用肖像显示。

If i change the project setting to show in portrait and landscape the gallery works fine but i can't control the other viewControllers to show only in portrait.

我尝试了几种方法,比如shouldAutoRotate但没有人工作。

I tried several methods like shouldAutoRotate but no one worked.

任何ideia如何解决?

Any ideia how to solve?

问候

编辑:

解决了:)

首先我配置项目以支持所有方向。
然后我将此方法添加到AppDelegate.m:

First i configured the project to support all orientation. Then i added this method to the AppDelegate.m:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}

之后我做的是阻止每个视图控制器中的方向,减去一个我想在风景和肖像方向。

After this what i did was to block orientation in each view controller, less the one i want to have orientation in landscape and portrait.

阻止方向的代码(iOS 7):

Code to block orientation (iOS 7):

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait);
}

感谢所有回答我的人:)

Thanks to everyone that answered me :)

推荐答案

在我的iPhone应用程序中,它仅支持纵向视图,但根据要求需要支持仅在视图上的横向视图,那时我使用以下方式和它帮助我:

In my app for iPhone its only support the portrait view only, but as per requirement need to support landscape view only for on view, at that time I use following way and its help me :

在你的应用程序委托.h

In your app delegate .h

@interface PlayWithWSWithLibAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

       BOOL flagOrientationAll;
}

@property (assign) BOOL flagOrientationAll;

在您的app delegate .m文件中添加以下方法

Add following method in your app delegate .m file

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    //NSLog(@"PlayWithWSWithLibAppDelegate -- supportedInterfaceOrientationsForWindow");
    if([UICommonUtils isiPad]){
        return UIInterfaceOrientationMaskAll;
    }else if(flagOrientationAll == YES){
        return UIInterfaceOrientationMaskAll;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

在视图中按照以下方式实施您要旋转的内容适用于iPhone设备的纵向和横向

Implement following way in your view which you want to rotate in both portrait and landscape both for iPhone device

-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.delegate = self;

    PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *) [[UIApplication sharedApplication] delegate];
    delegate.flagOrientationAll = YES;
 }
}

-(void)viewWillDisappear:(BOOL)animated
{
    //NSLog(@"viewWillDisappear -- Start");
     PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *)[[UIApplication sharedApplication] delegate];
        delegate.flagOrientationAll = NO;
}

另见这篇文章:如何在iphone中以横向模式设置其中一个屏幕?

这篇关于iOS 7界面方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆