最近我做了一个自定义警报,它是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
似乎都没有做任何事情。有没有人知道我在这里可能做错了什么?