2011-07-08 115 views
0

我正在開發基於iPad的程序。 我創建了新的模態UIViewController作爲表單模式不是全屏。 爲了調整視圖大小,我使用了以下代碼。 ...如何在旋轉屏幕時調整UIViewController的框架大小?

MyController* controller = [[MyController alloc] init]; 

controller.modalPresentationStyle = UIModalPresentationFormSheet; 

[self presentModalViewController : controller animated: YES]; 

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 

if (UIInterfaceOrientationIsPortrait(orientation)) 
    controller.view.superview.frame = CGRectMake(200, 100, 350, 600); 
else 
    controller.view.superview.frame = CGRectMake(100, 200, 600, 350); 

...

在myController的

,我抽放以下codeds爲didRotateFromInterfaceOrientation。

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
    if (fromInterfaceOrientation == orientation) 
     return; 
    if (UIInterfaceOrientationIsPortrait(orientation)) 
    { 
     self.view.frame = CGRectMake(0, 0, 350, 600); 
     self.view.superview.frame = CGRectMake(200, 100, 940, 628); 
    } 
    else 
    { 
     self.view.frame = CGRectMake(0, 0, 600, 350); 
     self.view.superview.frame = CGRectMake(100, 200, 600, 350); 
    } 
} 

但是當旋轉屏幕時,視圖不被調整大小,並且超視圖的寬度和高度具有意想不到的值。 請幫我解決問題。

回答

0

嘗試調試它,看看事實上你會得到什麼樣的方向。

你試過這樣嗎?

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 

    if (UIInterfaceOrientationIsPortrait(fromInterfaceOrientation)) 
    { 
     self.view.frame = CGRectMake(0, 0, 350, 600); 
     self.view.superview.frame = CGRectMake(200, 100, 940, 628); 
    } 
    else 
    { 
     self.view.frame = CGRectMake(0, 0, 600, 350); 
     self.view.superview.frame = CGRectMake(100, 200, 600, 350); 
    } 
} 

另請注意,有兩個portairt方向..

相關問題