convertPoint toView not getting absolute position on screen

1.3k Views Asked by At

I've read this iPhone - Get Position of UIView within entire UIWindow and others multiple times, but just cannot get my app to output to me the absolute position of something on the screen.

I have a scrollview that is jumping around and I'm trying figure out why. I'd like to be able to check where it is on screen (not its frame relative to its superview). I've tried the following:

CGPoint point = [scrollView.superview convertPoint:scrollView.frame.origin toView:nil];
NSLog(@"point is %f", point.y);

yet the console shows 0 as the Y position of the scroll view, despite that the fact that the scrollview is not in fact there on my screen, it is about a third of the way down. Does this method not give you the position of something in the absolute, entire 320x568 screen? I'm sure it's something small, but could someone point out what i'm missing?

2

There are 2 best solutions below

2
On

UIScrollView has a property called contentOffset. If you want to know the absolute position, you'll want to take the position of the view (that's in the scroll view) and minus the scroll view's contentOffset.

8
On
UIView *parentview =  [[UIApplication sharedApplication] window].rootViewController.view
CGPoint point = [parentview convertPoint:scrollView.frame.origin toView:nil];
NSLog(@"point is %f", point.y);