2011-07-08 160 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方向..

相关问题