简体   繁体   中英

How can i get CGRect values x,y,width,height after view is being autoresized?

I want x,y,widht,height values of view when it is autoresized automatically when orientation of ipad changes. How can i get that?

After the view has rotated you should be able to 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);
}

try this

- (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);
}

旋转后试试。

 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);
- (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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM