iphone - 旋转后重新定位UIWindow

标签 iphone ios cocoa-touch cgaffinetransform uiwindow

最近,我制作了一个自定义Alert,它是UIWindow的子类。当UIViewController处于横向时,我正在尝试旋转警报。我能够成功旋转它,但是在重新定位它以使其原点位于屏幕的左上角时遇到了麻烦。我下面有以下代码:

    CGRect mainScreenBounds = [[UIScreen mainScreen] bounds];
    UIDeviceOrientation deviceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    if (deviceOrientation == UIDeviceOrientationPortrait)
    {
        self.frame = CGRectMake(0,0, mainScreenBounds.size.width, mainScreenBounds.size.height);
    }
    else
    {
        self.frame = CGRectMake(0,0, mainScreenBounds.size.height, mainScreenBounds.size.width);

        if (deviceOrientation == UIDeviceOrientationLandscapeLeft)
        {
            self.transform = CGAffineTransformRotate(self.transform, M_PI / 2);
        }
        else
        {
            self.transform = CGAffineTransformRotate(self.transform, -M_PI / 2);
        }
        self.center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
    }

无论出于何种原因,设置center似乎都无济于事。有谁知道我在这里做错了什么吗?

最佳答案

一个应用程序中不应有多个UIWindow。已经有一个了。重新实现,从UIView继承。

来自UIWindow文档:“除非应用程序可以在外部设备屏幕上显示内容,否则应用程序只有一个窗口。”

关于iphone - 旋转后重新定位UIWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15885391/

相关文章:

iphone - 如何在 iPhone 中设置表格 View 单元格(基于导航的应用程序)的字体样式

iphone - 获取 UITableViewCell 上的 UITextField 的引用?

ios - 使用swift从解析中检索两个表中的数据

ios - Interface Builder 颜色与代码颜色不同

iphone - 从当前日期查找上周日的日期

iphone - 如何创建iOS模拟器

iphone - 重新加载/刷新 UIView

ios 无法更改 cellforrowatindexpath 中图像的角半径

ios - NSException 派生类或异常名称列表?

iphone - 在 iPhone 中返回上一个屏幕