How can I get the CGRect x, y, width, height values ​​after the view is authorized?

I want x, y, widht, view height values ​​when it automatically automates when the ipad orientation changes. How can i get this?

+4
source share
5 answers

After turning the view, you can get the new dimensions of the view.

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { CGRect myFrame = [self.view frame]; NSLog(@"height = %f", myFrame.size.height); NSLog(@"width = %f", myFrame.size.width); NSLog(@"x = %f", myFrame.origin.x); NSLog(@"y = %f", myFrame.origin.y); } 
+15
source
 NSLog(@"Rect is: ",NSStringFromCGRect(<#CGRect rect#>)); 
+4
source

try it

 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { float x = yourView.bounds.origin.x; float y = yourView.bounds.origin.y; float width = yourView.bounds.size.width; float height = yourView.bounds.size.height; NSLog(@"x=%f,y=%f,w=%f,h=%f",x,y,width,height); } 
+3
source

after trying to turn.

  NSLog(@"x = %.2f y = %.2f width = %.2f height = %.2f", view.frame.origin.x , view.frame.origin.y, view.frame.size.width, view.frame.size.height); 
0
source
 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { /*Subclasses may override this method to perform additional actions immediately after the rotation. For example, you might use this method to reenable view interactions, start media playback again, or turn on expensive drawing or live updates. By the time this method is called, the interfaceOrientation property is already set to the new orientation.*/ CGRect frame = self.view.frame } 
0
source

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


All Articles