首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS 7接口定向

iOS 7接口定向
EN

Stack Overflow用户
提问于 2013-12-06 11:01:47
回答 2查看 6.5K关注 0票数 6

我有一个应用程序,总是显示在肖像模式。

但在某个地方,我有一个媒体画廊,必须支持景观。

默认情况下,项目中支持的方向是纵向。正因为如此,画廊只能在肖像模式下显示。

如果我更改项目设置显示在肖像和景观,画廊工作良好,但我不能控制其他viewControllers只显示在肖像。

我尝试过几种方法,比如shouldAutoRotate,但没有人成功。

有什么办法解决吗?

问候

编辑:

已解决:)

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

代码语言:javascript
复制
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}

在此之后,我所做的就是阻止每个视图控制器的定向,而不是我想要的在景观和肖像中的定向。

代码块定向(iOS 7):

代码语言:javascript
复制
- (BOOL)shouldAutorotate
{
    return YES;
}

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

感谢所有回答我的人:)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-06 11:15:25

在我的iPhone应用程序中,它只支持人像视图,但根据需要只支持景观视图,当时我使用了以下方法并帮助我:

在应用程序委托.h中

代码语言:javascript
复制
@interface PlayWithWSWithLibAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

       BOOL flagOrientationAll;
}

@property (assign) BOOL flagOrientationAll;

在应用程序委托.m文件中添加以下方法

代码语言:javascript
复制
- (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设备的纵向和横向中都旋转

代码语言:javascript
复制
-(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;
}

也见此帖子:How to set one of the screens in landscape mode in iphone?

票数 7
EN

Stack Overflow用户

发布于 2013-12-06 11:16:43

您必须在显示媒体的同一视图Controller中创建另一个类。

在这种情况下,您可以指定您的方向,它将只支持景观定向,只有当您将介绍您的媒体。

我给你一个我的应用程序的例子,它只支持景观模式,但由于我采取了图像选择器,它只支持肖像模式,所以我改变了方向,只为该视图。

代码语言:javascript
复制
#pragma mark - Image PICKER

@interface NonRotatingUIImagePickerController : UIImagePickerController

@end

@implementation NonRotatingUIImagePickerController



- (BOOL)shouldAutorotate
{
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait ;
}

@end

然后,当我使用ImagePicker时,我使用了我创建的类的对象。

所以我定义如下。

代码语言:javascript
复制
UIImagePickerController* picker = [[NonRotatingUIImagePickerController alloc] init];

因此,对于图像拾荒者,它只显示在肖像模式。

你只需要改变景观,而不是肖像,如果你只想要改变你的特定视图的景观方向。

希望这能帮到你。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20422244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档