views:

84

answers:

2

I load the webview and set allowsScrolling to NO, but webview still shows scroll bars... Banging your head on your computer hurts a lot more now that MacBooks have sharp metal edges.

My code:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    NSString *webFolder = @"file:///<WebFolderPath>";
    [[[productWeb mainFrame] frameView] setAllowsScrolling:NO];
    [productWeb setFrameLoadDelegate:self];
    [[productWeb mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[webFolder stringByAppendingString:@"webpage.html"]]]];
}

I even setup the frame loading delegate to report about the scrolling status:

- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
    NSLog(@"Scrolling %@",[[frame frameView] allowsScrolling] ? @"Allowed" : @"Not Allowed");
    [[frame frameView] setAllowsScrolling:NO];
    NSLog(@"Scrolling %@",[[frame frameView] allowsScrolling] ? @"Allowed" : @"Not Allowed");
}

Which still gives me the unhappy:

2010-08-24 15:20:09.102 myApp[30437:a0f] Scrolling Allowed
2010-08-24 15:20:09.104 myApp[30437:a0f] Scrolling Not Allowed

And yet the scrollbars continue to show! Hopefully, it is something stupid I'm doing as I don't want to get any more blood on my laptop.

+1  A: 

Are you trying to prevent the user from scrolling the view at all? You can just set productWeb.userInteractionEnabled = NO. Or are you just trying to prevent the bars from showing when the user is scrolling?

Here's another thing you can try: inject some JavaScript into your UIWebView that disables the touchmove event:

[productWeb stringByEvaluatingJavaScriptFromString:@"document.ontouchmove = function(e){e.preventDefault();}"];

This leaves the user interaction enabled, but should prevent any scrolling.

Don
I think this is OS X, though, not iOS…
Wevah
Ah, good point - I must have iPhone on the brain.
Don
Yeah, it seems that the iPhone framework has been getting a lot more attention lately. There are a lot of features I'd love to see brought over to core cocoa.
BadPirate
A: 

I found I had to edit the HTML of the page I was trying to display to make sure that it was setup to take the full screen (and not more)... there was a DIV that had a minimum width set. Once I made sure the body had height = 100% and that none of the DIV's had a fixed or minimum width set that was smaller then the box I wanted to show it in everything came together :)

BadPirate