iOS 7 界面方向

标签 ios

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

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

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

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

我尝试了几种方法,例如 shouldAutoRotate,但没有一个起作用。

知道如何解决吗?

问候

编辑:

解决了:)

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

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

在此之后,我所做的是阻止每个 View Controller 中的方向,而不是我想要在横向和纵向方向上的方向。

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

- (BOOL)shouldAutorotate
{
    return YES;
}

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

感谢所有回答我的人:)

最佳答案

在我的 iPhone 应用程序中,它只支持纵向 View ,但根据要求只支持横向 View ,当时我使用以下方式,它帮助我:

在您的应用委托(delegate) .h 中

@interface PlayWithWSWithLibAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

       BOOL flagOrientationAll;
}

@property (assign) BOOL flagOrientationAll;

在您的应用程序委托(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 设备同时在纵向和横向旋转的 View 中实现以下方式

-(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?

关于iOS 7 界面方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20422244/

相关文章:

ios - 从完成处理程序中指定单个值

ios - 每当我添加 FlutterFire 包时,Firebase 就会停止工作

iphone - phonegap - webViewDidFinishLoad 没有被调用

ios - API 请求队列的最佳实践

为 UiTableview 安排多个操作的 iOS 最佳实践

ios - 在不丢失 socket 连接的情况下重命名 XIB 文件

ios - 如何在 iOS 中编写异步线程类?

objective-c - For 循环变量总是评估为真

ios - 设置UILabel的frame时,是否可以在代码中将其设置到superview的垂直和水平中心?

ios - UIDocumentInteractionController 不打开 pdf 文件