简体   繁体   English

原点控件在界面构建器中做了什么?

[英]What does the origin control do in interface builder?

In interface builder there is a control in the struts and springs inspector that is labeled origin. 在界面构建器中,在支柱和弹簧检查器中有一个标记为原点的控件。 What does this do and why does changing it for one object change it for ALL objects? 这样做以及为什么为一个对象更改它会为所有对象更改它?

原产地控制

As far as I can tell it doesn't have any real effect on the frame rectangle origin as the name implies. 据我所知,据我所知,它对框架矩形原点没有任何实际影响。 Let me explain: 让我解释:

Selecting a UILabel and changing the origin to be at the top right as in the photo above puts the frame origin at the point (280,11). 选择UILabel并将原点更改为如上图所示位于右上角,将帧原点放在该点(280,11)。 However, in code, when you actually ask the frame for it's origin it is given as (211,11) which corresponds to the top left corner of the frame. 但是,在代码中,当您实际询问帧的原点时,它被赋予(211,11),它对应于帧的左上角。 Therefore, changing the frame origin in interface builder appears to do absolutely nothing! 因此,在界面构建器中更改框架原点似乎绝对没有任何作用! What is going on here?! 这里发生了什么?!

It does nothing unless you're editing the fields immediately adjacent to it. 除非您正在编辑紧邻它的字段,否则它不会执行任何操作。 You'll note that the X and Y coordinates change depending on the anchor point you select for it; 您会注意到X和Y坐标会根据您为其选择的锚点而改变; that's meant to make it easier for you to align the object by its center or edge. 这意味着您可以更轻松地通过其中心或边缘对齐对象。

The reason it changes for all objects is that it doesn't actually affect anything about the object itself; 它为所有对象更改的原因是它实际上不会影响对象本身的任何内容; the “real” coordinate system remains the same regardless of the displayed X and Y values there. 无论在那里显示的X和Y值如何,“真实”坐标系保持不变。

On OS X, as Nathan says, the coordinate system has its origin at the bottom left and its coordinates increase up and to the right; 在OS X上,正如内森所说,坐标系的原点在左下方,其坐标向上和向右增加; on iOS, the origin is at the top left, and its coordinates increase to the bottom and right. 在iOS上,原点位于左上角,其坐标向下和向右增加。

i don't now the exact answer but i think that it has to do with the origin code you've set for that object like (just a example) 我现在不是确切的答案,但我认为它与您为该对象设置的原始代码有关(仅举例)

- (void) Button {

       CGRect frame = button.frame;
       frame.origin.x = 500; // new x coordinate
       frame.origin.y = 500; // new y coordinate
       button.frame = frame;
}

And maybe there is a way to set the frame.origin to a setting that would connect it to the origin tool in InterFace Builder 也许有一种方法可以将frame.origin设置为将其连接到InterFace Builder的原始工具的InterFace Builder

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaDrawingGuide/Transforms/Transforms.html https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaDrawingGuide/Transforms/Transforms.html

Cocoa uses a Cartesian coordinate system as its basic model for specifying coordinates. Cocoa使用笛卡尔坐标系作为指定坐标的基本模型。 The origin in this system is located in the lower-left corner of the current drawing space, with positive values extending along the axes up and to the right of the origin point. 此系统的原点位于当前绘图空间的左下角,正值沿轴向上和原点右侧延伸。 The root origin for the entire system is located in the lower-left corner of the screen containing the menu bar. 整个系统的根源位于包含菜单栏的屏幕的左下角。

If you were forced to draw all your content in screen coordinates—the coordinate system whose origin is located at the lower-left corner of the computer's primary screen—your code would be quite complex. 如果您被迫在屏幕坐标中绘制所有内容 - 坐标系统的原点位于计算机主屏幕的左下角 - 您的代码将非常复杂。 To simplify things, Cocoa sets up a local coordinate system whose origin is equal to the origin of the window or view that is about to draw. 为简化起见,Cocoa设置了一个局部坐标系,其原点等于即将绘制的窗口或视图的原点。 Subsequent drawing calls inside the window or view take place relative to this local coordinate system. 窗口或视图内的后续绘制调用相对于此局部坐标系进行。 Once the code finishes drawing, Cocoa and the underlying graphics system convert coordinates in the local coordinates back to screen coordinates so that the content can be composited with content from other applications and sent to the graphics hardware. 一旦代码完成绘制,Cocoa和底层图形系统将本地坐标中的坐标转换回屏幕坐标,以便内容可以与来自其他应用程序的内容合成并发送到图形硬件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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