【问题标题】:UIView transitions with wrong orientationUIView 转换方向错误
【发布时间】:2012-06-14 10:36:04
【问题描述】:

我有这段代码(Book1 是 UIViewController 类)

Book1 *book = [self.storyboard instantiateViewControllerWithIdentifier:@"Book1ID"];    
[UIView transitionFromView:self.view toView:book.view duration:1 options:UIViewAnimationOptionTransitionCurlDown completion:nil];

ViewController 加载但方向错误。它以纵向视图加载,但我希望它以横向加载。

我已经在 Book1 中有以下代码,但是一旦加载视图,所有自动旋转似乎都失败了。

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;}

如何在横向中加载此视图?

【问题讨论】:

  • 您的故事板设计是否处于横向模式?
  • 是的,但我发现我在新实例化的 UIView 上按下的任何按钮都会给我一个错误:消息发送到已释放的实例
  • 我修复了释放实例错误,但页面仍然无法在横向视图中打开
  • 这就是为什么因为您的整个设计处于纵向模式,并且在加载视图后更改设备方向时将调用方法-(BOOL)shouldAutorotateToInterfaceOrientation:,因此您必须在横向模式下设计视图才能启动它在风景模式下,或者您必须将您的父/根视图限制为仅风景模式
  • 太棒了,如何将其限制为横向?我只在我的设置中选择了横向选项,将我的故事板设置为横向并将应该旋转委托添加到我的类中。

标签: xcode uiview orientation storyboard


【解决方案1】:

我之前的方法没有发现问题,但我找到了另一种方法。

是这样的:

book = [self.storyboard instantiateViewControllerWithIdentifier:@"Book1ID"];
book.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:book animated:YES completion:^(void){}];

特别感谢 Aalok Parikh 的所有帮助

【讨论】:

    【解决方案2】:

    所以请执行以下操作:

    第一

    只需选择这两个方向作为支持的设备方向:)

    第二

    现在添加键图像中的最后一个 Initial interface orientation 以及列表中两个横向值中您想要的值

    第三

    现在将以下函数添加到所有控制器的 .m 文件中

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }
    

    第四次

    只需构建并运行您的项目 :)

    现在您的应用程序仅限于横向模式

    编码愉快:)

    【讨论】:

    • 首先感谢您的帮助和耐心。我完全按照这些说明进行操作,但过渡仍然显示肖像。自动旋转(例如我抬起 ipad 并转动它)也没有效果。就像类只被部分实例化,而额外的东西,比如委托等,失败了
    • transition still shows portait 是什么意思?启动时的视图仍然是纵向模式吗?这是真的吗?但它对我来说很好。
    • no 启动时的视图是横向的。当我尝试以编程方式加载第二个视图(如我发布的第一个代码块中)时,第二个视图以纵向显示并且自动旋转不起作用
    • 因此您必须使用第二个视图 .m 文件中的 第三个 步骤,该文件必须在 xib 或情节提要中以景观模式设计,问题将按以下方式解决我的知识
    • 是的,我已经这样做了。不过谢谢你的帮助,我真的很感激
    猜你喜欢
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    • 2016-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多