UIwebview / webkit scrolling

Discussion in 'iOS Programming' started by Craigy, Dec 18, 2010.

  1. Craigy macrumors 6502

    Joined:
    Jan 14, 2003
    Location:
    New Zealand
    #1
    Anyone found a way in a HTML document in a UIwebview to only allow horizontal scrolling.

    I can use the following to prevent all scrolling:

    document.ontouchmove = function(e){
    e.preventDefault();
    }

    but I want the document to be able to scroll horizontally only.

    Any ideas?

    Cheers
    Craig
     
  2. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #2
    Are you trying to stop the 'rubberband' -style bounce [1] that occurs when trying to scroll past the bottom of the content?

    Or do you have a webpage that is bigger than the space available [2], and want to disallow vertical scrolling? (Which, frankly, sounds a bit strange!)

    Code:
    for (id subview in webView.subviews) {
    	if ([[subview class] isSubclassOfClass: [UIScrollView class]]) {
    		UIScrollView* scrollView = (UIScrollView *)subview;
    		// disable rubberband bouncing [1]
    		scrollView.bounces = NO;
    		// adjust content height [2]
    		CGSize size = scrollView.contentSize;
    		scrollView.contentSize = CGSizeMake(size.width, myViewHeight);
    		break;
    	}
    }
    This code is unsatisfactory because step 2 requires that bounces are disabled, and that makes interacting with the page feel somewhat unnatural.

    Hope this helps :)
     

Share This Page