0

So i have a UIWebView that is meant to only scroll horizontally, and its in a UIScrollView that is only meant to scroll vertically. I have almost managed to achieve this, but i have a slight problem.

The UIWebiew's scroll content height is set to the height of the webviews frame, so that it wont scroll vertically, but even when this is the case, it still seems to consume the vertical scrolling event (sometimes), since i can see the side scroll bar show, but it wont scroll (and doesnt scroll the scrollview that the webview is contained in).

It needs to be like this because there are some elements that need to scroll vertically with the webview, but not horizontally (think of the safari app how the addressbar scrolls with the webview)

does anyone know how i would pass the vertical scroll event through but keep the horizontal scroll event for the UIWebView?

i had a look at this answer but its not quite what im looking for

update:

so typically just after i ask the question i find a suitable answer on another question... (had been searching for a few hours now) this answer should do the trick for me, ill give it a go and report back

Community
  • 1
  • 1
Fonix
  • 11,447
  • 3
  • 45
  • 74

2 Answers2

0

Just set

scrollView.alwaysBounceVertical = NO;
scrollView.contentSize = CGSizeMake(
    scrollView.frame.size.width, scrollView.contentSize.height);
scrollView.showsVerticalScrollIndicator = NO;

Edit: doesn't seems to work. Too bad..

Try implementing

- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gst 
    shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)gst2 {
    return YES;
}

..in your view containing the scrollView and webView, or even the scrollView itself (containing the webView).

Leonard Pauli
  • 2,662
  • 1
  • 23
  • 23
  • heh yep that is what i have at the moment, it still consumes the vertical scroll event though even though it cant actually scroll which is the problem – Fonix Jul 29 '13 at 10:15
0

So the solution i found that i posted in the question works for the most part, it does exactly what i need, but for some reason after a webpage loads, it scrolls the headerbar away showing just the webpage, which isnt the end of the world but its not pretty. it seems the event fires after the webViewDidFinishLoad: so i cant just reposition it back to the top. Ill keep tinkering around, maybe i can find out why its doing it.

Fonix
  • 11,447
  • 3
  • 45
  • 74
  • i dealt with the header jumping off the screen by putting it in a UIView animation so that it would animate off screen instead of jumping right off (apparently webviews automatically set their content offset to 0,0 when the page finishes loading) – Fonix Jul 30 '13 at 09:26
  • i also had a problem where after adding a subview to the webview's scrollview half the webpage would be unclickable, i fixed it by inserting the subview at position 0 (so its at the back in the view hierarchy), not sure why it works but it did. – Fonix Jul 30 '13 at 09:26