origin in visibleRect

Discussion in 'Mac Programming' started by func, Jul 10, 2009.

  1. macrumors newbie

    Joined:
    Jul 6, 2009
    #1
    Im trying to access the x and y positions of a view's origin (within a scrollview).

    NSPoint p = [self visibleRect].origin;
    NSLog(@"view's origin.x : %d", p.x);

    If I inspect the first line in the debugger, the value of origin.x is set to some value > 0, depending on it's location. But the NSLog line will always print "view's origin.x : 0" .

    What am I doing wrong here?
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    %d is for integers, but NSPoint's x and y values are floats, so use %f.
     
  3. thread starter macrumors newbie

    Joined:
    Jul 6, 2009
    #3
    Thank you for the fast response!

    Unfortunately it didnt solve the problem.
    Now it outputs 0.00000 instead :(
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    What is "self" here? Is it the document view of the scroll view? If so you could try [[self enclosingScrollView] documentVisibleRect] and see if that gives anything different (might not). Also [self bounds] might be what you need.
     
  5. thread starter macrumors newbie

    Joined:
    Jul 6, 2009
    #5
    Yeah, that solved it!

    self was referring to a custom openGLView and not the documentaionView.

    Thanks a lot!

    edit: Im a nub ;)
     
  6. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #6
    Turn on as many warnings as possible. The compiler could have told you about the %d problem.
     

Share This Page