views:

76

answers:

2

Hi, I want to get the origin of scrollView in the window coordinate system. For Example, presently, scollView origin is (0,51). But in window coordinate system it should be 51 + 44(navigation bar height)+20(status bar height) = 115. Means in window coordinate system the scrollView.frame.origin should be (0,115). I tried with convertPoint: methods but getting (0,51) or (0,0) sometimes. Please provide a solution to this. Thanks

+2  A: 

It sounds like your not converting between the proper views. A view's frame is set to the coordinates of it's superview, not its own internal coordinates. To find the origin of a view in a window, you need to a convert the origin in the view's superview to the window like so:

[[self superview] convertPoint:self.frame.origin toView:theWindow];
TechZen
I tried this code piece of code in viewDidLoad method, with self replaced by self.view and theWindow replaced by self.view.window,but it is giving (0,0) as the output
I would check that the window property of the view is not nil. It often is.
TechZen
Thanks for replying. How to deal with this problem. I tried replacing self.view.window with [UIApplication sharedApplication].keywindow but to no avail.
A: 

I tried with TechZen solution but to no avail. Instead of converting scrollView's origin,I referred to apple docs UIWindow class Reference and converted the endCenter of the keyboard to my view's coordinate system by using this code [self.view convertPoint:endCentre fromView:[UIApplication sharedApplication].keyWindow]. This piece of code worked and hence solved my problem. However, the question still remains as to why it does not gives the proper coordinate of scrollView.origin.So, basically I got a workaround by converting keyboard endcenter instead of scrollView.origin. Oh, and I was doing all this stuff in order to calculate my scrollView's new height when keyboard appears on screen. So, if somebody has a solution to this problem or any better solution, Please let all of us know.