ios - 在 iOS Interface Builder 中使用 StoryBoard 支持横向和纵向

标签 ios storyboard landscape-portrait

我开发了一个应用程序,它使用 GPOrientationKit 支持纵向和横向。我按照以下链接来完成应用程序的所有页面以支持这两种方向。

http://logisian.blogspot.in/

我用 XIB 或 NIB 文件做了那个应用程序。现在,我正在开发一个带有 Storyboard的应用程序。我不知道如何制作支持 Storyboard两个方向的应用程序。 GOrientationKit 适用于 XIB 文件。但是我在 Storyboard中苦苦挣扎。我需要 Storyboard中的 GPOrientationKit 等功能。请帮助我做到这一点。

提前致谢。

最佳答案

只需将两个 subview 添加到您的 Controller 的主视图,例如纵向 View 和横向 View ,并在您的方向改变时在它们之间切换......我有这样的东西

在你的 viewWillAppear 方法中添加这个

-(void)viewDidAppear:(BOOL)animated{

        if(UIDeviceOrientationIsPortrait(self.interfaceOrientation))
    {

//Keep LAndscape View Hidden
    self.portraitVIew.frame=self.view.frame;
    [self.view addSubview:self.portraitVIew];
    }else{


//Keep portrait View Hidden

    self.landscapeView.frame=self.view.frame;
    [self.view addSubview:self.landscapeView];
    }
    self.view.autoresizesSubviews = YES;

     } 
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(deviceOrientationDidChangeNotification:)
     name:UIDeviceOrientationDidChangeNotification
     object:nil];



}

然后实现方法deviceOrientationDidChangeNotification例如

- (void)deviceOrientationDidChangeNotification:(NSNotification*)note
{


        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
        if(UIDeviceOrientationIsLandscape(self.interfaceOrientation))
        {
//Keep portrait View Hidden

            NSLog(@"YUP THIS IS LANDSCAPE");
            self.landscapeView.hidden=NO;
            self.landscapeView.frame=self.view.frame;
            [self.portraitVIew removeFromSuperview];
            ///self.landscapeView.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);


            [self.view addSubview:self.landscapeView];
        }else {
//Keep LAndscape View Hidden

            self.landscapeView.hidden=YES;
            self.portraitVIew.frame=self.view.frame;
            NSLog(@"Portrait");

            [self.view addSubview:self.portraitVIew];
        }
}

关于ios - 在 iOS Interface Builder 中使用 StoryBoard 支持横向和纵向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24927213/

相关文章:

swift - 某些设备上不需要的 ios 8 应用程序轮换

ios - 使用 MFMessageComposeViewController 时请求访问文本数据的权限

ios - 给定带有多行标签的 Collection View 单元格的宽度,如何获得首选的 AutoLayout 高度?

storyboard - 在 Storyboard上, View 和传递数据

xcode - Xcode StoryboardSegue循环回到同一 View

android - Google Play 游戏服务 - 从横向模式的应用启动 google+ 登录流程

ios - 圆形,3 色渐变,动画进度 View

ios - 我可以解决 UIWebView 中的 iOS 8 Voiceover 错误吗?

ios - 为什么 UITableViewCell 初始化在 initWithCoder 中不起作用

ios - 在 iOS 9 中强制 UIViewController 为横向