【问题标题】:Programmatically change view orientation without rotating ipad以编程方式更改视图方向而无需旋转 ipad
【发布时间】:2011-08-10 09:15:56
【问题描述】:

我想根据某些条件旋转 ViewController。 shouldAutorotateToInterfaceOrientation 的问题是视图总是以纵向/横向方向开始(在 Interface Builder 中设置),用户必须旋转 ipad 才能使用正确的模式....我怎样才能改变这种行为? 谢谢。

【问题讨论】:

    标签: iphone objective-c ipad rotation orientation


    【解决方案1】:

    对视图应用变换。

    view.transform = CGAffineTransformMakeRotation(M_PI);

    您可以使用 UIView 动画来为更改设置动画。

    【讨论】:

    • 我会尽力让你知道的。谢谢你。另一件事:这会使用 Interf Builder 中定义的自动调整规则吗?
    • 不,上面的代码不会改变视图的大小,它只会旋转它。请注意,根据文档,应用了非身份转换的视图在 frame 属性中具有未定义的值。
    【解决方案2】:

    您也可以尝试在 info.plist 中添加此内容:

    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    

    来源:ipad default-landscape not displaying

    【讨论】:

      【解决方案3】:
      [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
      

      这将在不旋转设备的情况下将方向更改为纵向模式。同样您可以使用 景观也

      【讨论】:

      • 这可行,但它不在 api 文档中,因此您可能违反了 Apple 关于私有 api 的规则,如果您使用它,您的应用可能会被拒绝。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多