ios 在自动调整视图大小后,如何获得 CGRect 值 x、y、width、height?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9665395/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:15:38  来源:igfitidea点击:

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

iphoneobjective-ciosipad

提问by sam

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

我想要 x,y,widht,height 视图的值,当它在 ipad 的方向改变时自动调整大小。我怎么能得到那个?

回答by Peter Kelly

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

回答by Sanket Pandya

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

回答by janusfidel

after the rotation try.

轮换后试试。

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

回答by Krrish

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