Skip to main content

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?





Origin Control





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). 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. Therefore, changing the frame origin in interface builder appears to do absolutely nothing! What is going on here?!


Comments

  1. 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; 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.

    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; on iOS, the origin is at the top left, and its coordinates increase to the bottom and right.

    ReplyDelete
  2. 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

    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. 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.
    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.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.