Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convertPoint toView not getting absolute position on screen

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?

like image 453
skinsfan00atg Avatar asked Feb 02 '26 18:02

skinsfan00atg


1 Answers

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.

like image 85
Guy Kogus Avatar answered Feb 05 '26 08:02

Guy Kogus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!