如何使视图中的所有内容居中对齐。当我旋转iPad时,内容并没有自动居中对齐,该如何解决这个问题?感谢!
提供 didRotateFromInterfaceOrientation
方法的实现,并将所有子视图居中。
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
for(UIView *subview in [self.view subviews]) {
subview.center = self.view.center;
}
}
你应该以编程方式更改内容框架,以适应横向和纵向模式。你可以尝试以下方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){
// set contents' frame for landscape
}
else {
// set contents' frame for portrait
}
return YES;
}