2010-12-21 36 views
4

如何居中对齐所有视图的内容。当我旋转iPad的内容不对齐中心它自己如何解决这个问题??UIView - 中心对齐UIView的所有内容?

谢谢!

+0

你使用nib文件还是以编程方式添加它? – shannoga 2010-12-21 05:35:06

+0

我为此使用了nib文件。我知道这里有对齐属性,但通过设置这个我仍然面临同样的问题,在旋转后。 – 2010-12-21 05:49:23

回答

7

提供的didRotateFromInterfaceOrientation方法和中心的所有子视图的实现。

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    for(UIView *subview in [self.view subviews]) { 
     subview.center = self.view.center; 
    } 
} 
0

您应该为横向和纵向模式更改programmatic-ally内容的框架。 你可以试试这个为:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){ 
     // set contents' frame for landscape 
    } 

    else { 
     // set contents' frame for portrait 

    } 

    return YES; 
}