繁体   English   中英

检测lanscap模式并显示UIImage

[英]Detect the lanscap mode and show an UIImage

我正在开发仅使用纵向模式的iOS应用程序。 我想在用户转动iPhone(横向模式)时在我的应用程序的所有视图中显示图像(320 * 480)

我该怎么做?

您可以在UIViewController方法didRotateFromInterfaceOrientation:完成此操作,该方法将在用户旋转设备后立即调用。

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    if (self.interfaceOrientation != UIInterfaceOrientationPortrait) {
        // add image to self.view
    } else {
        // remove image from self.view
    }
}

您可以在每个应用程序的视图控制器中实现此方法。 或者,您可以在UIViewController的自定义子类中实现此功能,然后让所有应用程序的视图控制器都从自定义视图控制器继承。

编辑

正如@David Dunham所建议的那样,如果您要做的就是阻止应用程序在用户旋转设备时更改方向,则可以通过实现UIViewController方法shouldAutorotateToInterfaceOrientation:轻松实现。 对于您要支持的每个方向,该方法都应返回YES ,而对于不希望支持的任何方向,则返回NO

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // only allow portrait orientation
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

shouldAutorotateToInterfaceOrientation:返回NO会更容易吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM