PDA

View Full Version : origin in visibleRect




func
Jul 10, 2009, 08:36 AM
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?



kainjow
Jul 10, 2009, 08:58 AM
%d is for integers, but NSPoint's x and y values are floats, so use %f.

func
Jul 10, 2009, 09:05 AM
Thank you for the fast response!

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

kainjow
Jul 10, 2009, 09:09 AM
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.

func
Jul 10, 2009, 09:19 AM
Yeah, that solved it!

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

Thanks a lot!

edit: Im a nub ;)

gnasher729
Jul 10, 2009, 11:45 AM
Yeah, that solved it!

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

Thanks a lot!

edit: Im a nub ;)

Turn on as many warnings as possible. The compiler could have told you about the %d problem.