xcode UIView - 居中对齐 UIView 的所有内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4496538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIView - Center alignment all the contents of UIView?
提问by Nitesh M
How to center alignment all the contents of view. When i am rotating iPad contents are not align center it self how to resolve this problem??
如何居中对齐视图的所有内容。当我旋转 iPad 内容时没有对齐中心它自己如何解决这个问题?
Thanks!!!
谢谢!!!
回答by Anurag
Provide an implementation of the didRotateFromInterfaceOrientation
method and center all subviews.
提供该didRotateFromInterfaceOrientation
方法的实现并将所有子视图居中。
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
for(UIView *subview in [self.view subviews]) {
subview.center = self.view.center;
}
}
回答by iPhoneDv
You should change programmatic-ally the contents' frame for both Landscape and portrait modes. You can try this as:
您应该以编程方式更改横向和纵向模式的内容框架。你可以试试这个:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){
// set contents' frame for landscape
}
else {
// set contents' frame for portrait
}
return YES;
}