最近,我制作了一个自定义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/