Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScrollOffset in UIWebView?

I'm having a really hard time understanding delegates and object inheritance (if I may use this word) and I think I need a simple (or so I think) thing: catch scrollViewDidScroll event in UIWebView and get offset (basically, just to know if scroll is not on top/bottom, so I could hide navigation and tab bars).

Is there any way I could do it? I already using UIWebviewDelegate in my view controller to "shouldStartLoadWithRequest". Maybe I could some how use UIScrollViewDelegate too for scrollViewDidScroll? If yes, then how?

I really have trouble understanding delegates. I've red some articles, but still, in practice, I can't manage to use them.

Any help or info would be lovely.

Thank you in advance!

like image 434
sniurkst Avatar asked Oct 22 '09 03:10

sniurkst


1 Answers

To retrieve scroll events on UIWebView I personnaly use this code to get the scrollview that is inside the UIWebView :

- (void) addScrollViewListener
{
    UIScrollView* currentScrollView;
    for (UIView* subView in self.myWebView.subviews) {
        if ([subView isKindOfClass:[UIScrollView class]]) {
            currentScrollView = (UIScrollView*)subView;
            currentScrollView.delegate = self;
        }
    }
}

It's working. You can also use it to call [currentScrollView setContentOffset:offSet animated:YES]; The only problem may be not to pass Apple code checking. I don't know yet since I'm still in coding phase.

[UPDATE] The app with this code is in the app store for 4 months now and used by 40 000 users. I didn't have any trouble [UPDATE]

like image 82
CedricSoubrie Avatar answered Sep 21 '22 18:09

CedricSoubrie