2013-04-08 70 views
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似乎並沒有這樣做不管出於什麼原因什麼。有沒有人有任何線索我可能在這裏做錯了?

回答

-5

應用程序中不應該有多個UIWindow。已經有一個。重新實現,從UIView子類化。

來自UIWindow文檔:「除非應用程序可以在外部設備屏幕上顯示內容,否則應用程序只有一個窗口。」

+0

我需要一個UIWindow,所以我可以把它放在狀態欄上,就像UIAlertView一樣。 – 2013-04-08 19:48:44

+0

如果您想讓狀態欄消失,請將其設置爲消失 – bshirley 2013-04-09 20:44:06

+0

不想讓它消失,您知道警報何時出現時會在屏幕上留下黑色色調嗎?這就是我要做的,需要一個UIWindow。 – 2013-04-09 22:44:19