UIView - Center aligns all contents of a UIView?

How to center the alignment of the entire contents of a view. When I rotate the iPad, the content does not align the center, but how to solve this problem?

Thanks!!!

+4
source share
2 answers

Provide an implementation of the didRotateFromInterfaceOrientation method and center all subzones.

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

You must change the program-oriented content 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; } 
0
source

Source: https://habr.com/ru/post/1332860/


All Articles