2010-12-21 37 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; 
}