2
最近我做了一個自定義警報,它是UIWindow
的一個子類。我試圖在UIViewController
處於橫向方向時旋轉警報。我可以成功旋轉它,但是我無法重新定位它,以便它的原點位於屏幕的左上角。下面我有以下代碼:旋轉後重新定位UIWindow
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,所以我可以把它放在狀態欄上,就像UIAlertView一樣。 – 2013-04-08 19:48:44
如果您想讓狀態欄消失,請將其設置爲消失 – bshirley 2013-04-09 20:44:06
不想讓它消失,您知道警報何時出現時會在屏幕上留下黑色色調嗎?這就是我要做的,需要一個UIWindow。 – 2013-04-09 22:44:19