Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Craigy

macrumors 6502
Original poster
Jan 14, 2003
403
48
New Zealand
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
 
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 :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.