Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIButton的坐标错误_Ios_Uibutton_Storyboard_Coordinates_Bounds - Fatal编程技术网

Ios UIButton的坐标错误

Ios UIButton的坐标错误,ios,uibutton,storyboard,coordinates,bounds,Ios,Uibutton,Storyboard,Coordinates,Bounds,在一个场景中,我有一个UIButton\u btnBuffalo(除其他外),在实用工具检查器中有以下坐标: 在我的ViewController中,我尝试将按钮设置为矩形,如下所示: CGRect btnRect = _btnBuffalo.bounds; 不幸的是,我通过NSLog得到了这样的结果: btnRect x: 0.000000, y: 0.000000, w: 160.000000, h: 120.000000 我真的明白为什么x和y是0.000000,有什么想法吗

在一个场景中,我有一个UIButton\u btnBuffalo(除其他外),在实用工具检查器中有以下坐标:

在我的ViewController中,我尝试将按钮设置为矩形,如下所示:

 CGRect btnRect = _btnBuffalo.bounds;
不幸的是,我通过NSLog得到了这样的结果:

btnRect x: 0.000000,  y: 0.000000,  w: 160.000000,  h: 120.000000

我真的明白为什么x和y是0.000000,有什么想法吗

您应该调用
\u btnBuffalo.frame
而不是
\u btnBuffalo.bounds
bounds
对于任何视图都始终返回
zero origin

您应该调用
\u btnBuffalo.frame
而不是
\u btnBuffalo.bounds
<代码>边界始终为任何视图返回
零原点

框架属性指定视图在其superview坐标系中的大小和位置。因此,必须这样做

CGRect btnRect = _btnBuffalo.frame;
NSLog(@"%f ,%f ,%f ,%f",btnRect.origin.x,btnRect.origin.y,btnRect.size.width,btnRect.size.height);

frame
属性指定视图在其superview坐标系中的大小和位置

CGRect btnRect = _btnBuffalo.frame;
NSLog(@"%f ,%f ,%f ,%f",btnRect.origin.x,btnRect.origin.y,btnRect.size.width,btnRect.size.height);

这正是我所做的。这正是我所做的。非常感谢,frame是解决方案。非常感谢,frame是解决方案。