iOS 7界面方向

 ww心海星空 发布于 2023-02-12 14:41

我有一个始终以纵向模式显示的应用程序.

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

默认情况下,项目中支持的方向是纵向.因此,画廊仅以肖像模式显示.

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

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

任何ideia怎么解决?

问候

编辑:

解决了 :)

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

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

在此之后,我所做的是阻止每个视图控制器中的方向,减少我想要在横向和纵向中定向的那个.

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

- (BOOL)shouldAutorotate
{
    return YES;
}

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

感谢大家回答我:)

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

    在您的应用代表.h

    @interface PlayWithWSWithLibAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
    
           BOOL flagOrientationAll;
    }
    
    @property (assign) BOOL flagOrientationAll;
    

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

    - (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设备中以纵向和横向旋转

    -(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中以横向模式设置其中一个屏幕?

    2023-02-12 14:47 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有