Reputation: 16673
I currently have the following code to check how far it is until the end of the page is reached;
var untilPageEnd = $(document).height() - (window.pageYOffset + window.innerHeight);
In apps previous to iOS7 this would work perfectly. But now in my iOS7 app window.pageYOffset
returns 0 all the time. Is there any known solution for this?
window.pageYOffset works in the safari browser but not in the UIWebView
Upvotes: 0
Views: 1015
Reputation: 36
If you overwrite the UIScrollViewDelegate on UIWebView?
In iOS7, you need modify like that
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[super scrollViewDidScroll:scrollView];
//TO DO
//code goes here
}
Upvotes: 2
Reputation: 11
I am having the same issue and have given up on window.pageYOffset for the time being under iOS7 – the same code had worked for me since iOS3!
My solution: I have a subclass of UIWebView that I use that implements the
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
method & in that I have
CGFloat newOffY = scrollView.contentOffset.y + topLength
with topLength being set from the containing UIViewController via:
CGFloat topLength = 0;
CGFloat bottomLength = 0;
if([self respondsToSelector:@selector(topLayoutGuide)] && !self.isFullScreen) {
topLength = [[self topLayoutGuide] length];
bottomLength = [[self bottomLayoutGuide] length];
}
You can then pass the newOffY
back into your UIWebView for use in your javascript.
Yes, it's a hack, but it's how I'm getting this to work right now under iOS7. :/
(My testing has produced a theory that either window.pageYOffset is broken right now due to the new topLayoutGuide stuff in iOS7 or that Apple have redone how UIWebViews are implemented and you are now scrolling the UIScrollView rather than the UIWebView & so the javascript cannot detect the scrolling due to the scrolling happening at a lower level?)
Upvotes: 0