Advertise Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

sdkIQ for iPhone
($4.99)

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Dual Matches
($0.99)

Calcuccino Programmers' Calculator
($2.99)

SDKtoday
(free)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-01-2008, 11:37 AM   #1 (permalink)
New Member
 
Join Date: Apr 2008
Location: Onomatopoeia, Lugubriousylvania
Posts: 225
Default Turn off scrolling (bounces) in UIWebView?

I'm embedding a UIWebView within one of my view controllers, and I'd like to prevent the view from "bouncing" every time the user taps on it. (The UIWebView behaves much like a UIScrollView with bounces turned on.) The frame I've provided for the UIWebView is big enough to fit its entire contents easily.

Does anyone know a way to lock down the UIWebView so it doesn't try to scroll like this?
bonehead is offline   Reply With Quote
Old 05-01-2008, 12:17 PM   #2 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 802
Default Re: Turn off scrolling (bounces) in UIWebView?

There are bounce settings for UIScroll that you should be able to apply to anything that inherits from it.
scottiphone is offline   Reply With Quote
Old 05-01-2008, 12:49 PM   #3 (permalink)
New Member
 
Join Date: Apr 2008
Location: Onomatopoeia, Lugubriousylvania
Posts: 225
Default Re: Turn off scrolling (bounces) in UIWebView?

Quote:
Originally Posted by scottiphone
There are bounce settings for UIScroll that you should be able to apply to anything that inherits from it.
Good point-- but UIWebView doesn't inherit from UIScrollView (it's just a UIView subclass).
bonehead is offline   Reply With Quote
Old 05-01-2008, 01:59 PM   #4 (permalink)
Registered Member
 
Join Date: Apr 2008
Posts: 57
Default Re: Turn off scrolling (bounces) in UIWebView?

Actually I'd like to do the same thing to a UITableView that has two (and only two) rows in it (for editing)... it's kind of annoying when you can swipe it and it bounces a little.
brianr is offline   Reply With Quote
Old 05-01-2008, 03:05 PM   #5 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 802
Default Re: Turn off scrolling (bounces) in UIWebView?

TableView does inherit from ScrollView so you should be able to control it directly.

Surprised webview doesn't as well. You could override the touches or better yet send in a bug report if it's something you think would be useful.
scottiphone is offline   Reply With Quote
Old 07-25-2008, 12:22 PM   #6 (permalink)
Not So Junior Member
 
Join Date: Jul 2008
Posts: 4
Default Answer (Tested and Working)

Greetings,

Though I have not found a way to turn this off through the SDK, I HAVE found a way to turn this off from your web content.

Using JavaScript just add this:

For jQuery users:

Code:
$().ready(function(){
    document.ontouchmove = function(e){ e.preventDefault(); }
});
And everyone else:

Code:
document.onload = function(){
    document.ontouchmove = function(e){ e.preventDefault(); }
};
Enjoy,

- Peter Schmalfeldt

Last edited by MrMidi; 08-07-2008 at 02:07 AM.
MrMidi is offline   Reply With Quote
Old 07-25-2008, 11:33 PM   #7 (permalink)
Senior Member
 
MaCeXpErTo's Avatar
 
Join Date: Jul 2008
Posts: 146
Default

Quote:
Originally Posted by bonehead View Post
I'm embedding a UIWebView within one of my view controllers, and I'd like to prevent the view from "bouncing" every time the user taps on it. (The UIWebView behaves much like a UIScrollView with bounces turned on.) The frame I've provided for the UIWebView is big enough to fit its entire contents easily.

Does anyone know a way to lock down the UIWebView so it doesn't try to scroll like this?
I think all you have to do is use a boolean value that controls whether the view bounces past the edge of content and back again.

I would use: @property(nonatomic) BOOL bounces

If the value is NO, scrolling stops immediately at the content boundary without bouncing.

I don't know if this is correct or not but I hope it helps.
MaCeXpErTo is offline   Reply With Quote
Old 08-07-2008, 01:06 AM   #8 (permalink)
Registered Member
 
Marco's Avatar
 
Join Date: Apr 2008
Posts: 57
Default

MaCeXpErTo,

Can you give an example on how to use the @property(nonatomic) BOOL bounces to stop the UIWebView from bouncing?

Thanks
__________________
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org
Marco is offline   Reply With Quote
Old 09-11-2008, 11:19 AM   #9 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 169
Default

Quote:
Originally Posted by brianr View Post
Actually I'd like to do the same thing to a UITableView that has two (and only two) rows in it (for editing)... it's kind of annoying when you can swipe it and it bounces a little.
Im having this same problem and everything that ive tried doesnt seem to work....anyone have an example of how to do this for UITableView?

Basically, I want to get rid of the bounces. I tried setting up the BOOL, but it didnt seem to work.
RockStrongo is offline   Reply With Quote
Old 12-08-2008, 11:04 PM   #10 (permalink)
Registered Member
 
Join Date: May 2008
Location: New York City, NY
Posts: 177
Default

I'm in a similar situation, my UIWebView is horizontally 1000px wide, and no bouncing there, but it still bounces vertically for some reason - even though it is 100px only 100px tall - the UIWebView size is 320px x 100px -

not sure why it wants to bounce vertically?

Anyone have any success with this? I can't turn off the default behavior in touchesmoved because I do need it for scrolling horizontally. I was also surprised that UIWebView does not inherit from UIScrollView.

Thanks
markww is offline   Reply With Quote
Old 04-25-2009, 05:41 PM   #11 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 2
Default

Quote:
Originally Posted by markww View Post
I'm in a similar situation, my UIWebView is horizontally 1000px wide, and no bouncing there, but it still bounces vertically for some reason - even though it is 100px only 100px tall - the UIWebView size is 320px x 100px -

not sure why it wants to bounce vertically?

Anyone have any success with this? I can't turn off the default behavior in touchesmoved because I do need it for scrolling horizontally. I was also surprised that UIWebView does not inherit from UIScrollView.

Thanks
MaCeXpErTo, probably shouldn't try to answer things that you really have no clue on, there is no boucnes property in the UIWebView header and saying there is doesn't help anyone it just confuses people.

There is currently no way in the SDK to prevent the bounceing of a UIWebView, if the javascript fix works then that might be your best bet.

Another option would be to set the UIWebView at the full height of the content and then put that in a UIScrollView and set that contentHeight to the height of your viewable area. The downside to this is I doubt it will render a webview greater than 1000 pixels height.

Hope that helps.
coolblade is offline   Reply With Quote
Old 04-25-2009, 09:08 PM   #12 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 2
Default

This seems to work too (although it's not part of the API):

Code:
@interface UIScrollView (extended)
- (void)setAllowsRubberBanding:(BOOL)allowsRubberBanding;
@end

@implementation InfoViewController

- (void)viewDidLoad{
	[(UIScrollView*)[webview.subviews objectAtIndex:0]	 setAllowsRubberBanding:NO];
}

@end
Quote:
Originally Posted by coolblade View Post
MaCeXpErTo, probably shouldn't try to answer things that you really have no clue on, there is no boucnes property in the UIWebView header and saying there is doesn't help anyone it just confuses people.

There is currently no way in the SDK to prevent the bounceing of a UIWebView, if the javascript fix works then that might be your best bet.

Another option would be to set the UIWebView at the full height of the content and then put that in a UIScrollView and set that contentHeight to the height of your viewable area. The downside to this is I doubt it will render a webview greater than 1000 pixels height.

Hope that helps.
coolblade is offline   Reply With Quote
Old 05-02-2009, 02:12 AM   #13 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 2
Default

This works...

Thanks for the info.

Quote:
Originally Posted by coolblade View Post
This seems to work too (although it's not part of the API):

Code:
@interface UIScrollView (extended)
- (void)setAllowsRubberBanding:(BOOL)allowsRubberBanding;
@end

@implementation InfoViewController

- (void)viewDidLoad{
	[(UIScrollView*)[webview.subviews objectAtIndex:0]	 setAllowsRubberBanding:NO];
}

@end
rajeshgautam is offline   Reply With Quote
Old 07-15-2009, 12:57 PM   #14 (permalink)
FlipConversionDesign
 
Join Date: Aug 2008
Location: Orangeville, Ontario
Posts: 83
Send a message via MSN to flipconversion
Default

Quote:
Originally Posted by rajeshgautam View Post
This works...

Thanks for the info.

Just wanted to say thanks to coolblade, this works for me too. I wonder why it's not in the API =/
flipconversion is offline   Reply With Quote
Old 07-17-2009, 08:20 PM   #15 (permalink)
Registered Member
 
krye's Avatar
 
Join Date: Jan 2009
Location: NY, USA
Posts: 275
Default

Quote:
Originally Posted by rajeshgautam View Post
This works...

Thanks for the info.
Hey, for
Code:
[(UIScrollView*)[webview.subviews objectAtIndex:0]	 setAllowsRubberBanding:NO];
I get a warning "UIScrollView may not respond to '-setAllowsRubberBanding." (Messages without a matching method signature will be assumed t return 'id' and accept '...' as arguments.)"

Same thing if i change it to UIWebView. But it works. There is no longer a bounce on my WebView. Is it OK to disregard the warning?
krye is offline   Reply With Quote
Old 11-23-2009, 08:23 PM   #16 (permalink)
Registered Member
 
krye's Avatar
 
Join Date: Jan 2009
Location: NY, USA
Posts: 275
Default

FYI: People are getting rejected for this

From Apple email:
"The non-public API that is included in your applications is setAllowsRubberBanding"
krye is offline   Reply With Quote
Old 12-01-2009, 07:58 PM   #17 (permalink)
V42
Registered Member
 
Join Date: Dec 2009
Posts: 2
Default Allow scroll only when necessary

Quote:
Originally Posted by krye View Post
FYI: People are getting rejected for this

From Apple email:
"The non-public API that is included in your applications is setAllowsRubberBanding"
I just got a rejection email for this reason. In case it helps anyone else, I figured out a solution that works for my needs. This solution is based on the javascript approach described earlier in this thread by MrMidi. The difference is that it disables scrolling/rubberbanding only when the content can fit entirely within the web view. If the content is larger than will fit, scrolling & rubberbanding are allowed.

Code:
<html>
  <head>
    <script>
      document.ontouchmove = function(event) {
        if (document.body.scrollHeight == document.body.clientHeight) event.preventDefault();
      }
    </script>
  </head>
  <body>
    <p>No scrolling for you!</p>
  </body>
</html>
V42 is offline   Reply With Quote
Old 12-01-2009, 11:20 PM   #18 (permalink)
Registered Member
 
krye's Avatar
 
Join Date: Jan 2009
Location: NY, USA
Posts: 275
Default

Quote:
Originally Posted by V42 View Post
I just got a rejection email for this reason. In case it helps anyone else, I figured out a solution that works for my needs. This solution is based on the javascript approach described earlier in this thread by MrMidi. The difference is that it disables scrolling/rubberbanding only when the content can fit entirely within the web view. If the content is larger than will fit, scrolling & rubberbanding are allowed.

Code:
<html>
  <head>
    <script>
      document.ontouchmove = function(event) {
        if (document.body.scrollHeight == document.body.clientHeight) event.preventDefault();
      }
    </script>
  </head>
  <body>
    <p>No scrolling for you!</p>
  </body>
</html>
Cool, thank. I'll try that out.
krye is offline   Reply With Quote
Old 12-02-2009, 05:38 AM   #19 (permalink)
Registered Member
 
kelvinkao's Avatar
 
Join Date: Jul 2009
Location: Los Angeles
Posts: 238
Send a message via AIM to kelvinkao
Default

I would just put a transparent view on top of it to prevent the user from interacting with it. Yeah, I know, it's a hack.
kelvinkao is offline   Reply With Quote
Old 12-02-2009, 01:43 PM   #20 (permalink)
V42
Registered Member
 
Join Date: Dec 2009
Posts: 2
Default Scrolling fix for OS v2.2.1

Quote:
Originally Posted by V42 View Post
I just got a rejection email for this reason. In case it helps anyone else, I figured out a solution that works for my needs. This solution is based on the javascript approach described earlier in this thread by MrMidi. The difference is that it disables scrolling/rubberbanding only when the content can fit entirely within the web view. If the content is larger than will fit, scrolling & rubberbanding are allowed.

Code:
<html>
  <head>
    <script>
      document.ontouchmove = function(event) {
        if (document.body.scrollHeight == document.body.clientHeight) event.preventDefault();
      }
    </script>
  </head>
  <body>
    <p>No scrolling for you!</p>
  </body>
</html>
I ran into a small problem with this approach. Apparently, there is a difference in behavior with regards to the clientHeight attribute in different versions of the iPhone OS. The above code works fine in v3.0, but not in v2.2.1. For some reason, in v2.2.1, the clientHeight is always equal to the scrollHeight, so the code would prevent scrolling in all cases. I was able to fix this by using window.innerHeight instead of document.body.clientHeight.
V42 is offline   Reply With Quote
Old 07-09-2010, 12:43 PM   #21 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 3
Default Another way to stop scrolling!

Since I was just using the UIWebView to display text, what worked for me was to set webView.userInteractionEnabled=NO.

Some more hints here: How To Place a UIWebView inside a UIScrollViewJuggleware Developers' Blog | Juggleware Developers' Blog
juggleware is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to show "Turn off Airplane Mode..." network dialog? bonehead iPhone SDK Development 8 01-18-2010 10:37 PM
Beta 8 - Tab Bar Application with UIWebView Marco iPhone SDK Development 7 06-02-2009 11:37 PM
UIWebView tkilmer iPhone SDK Development 3 08-15-2008 10:15 AM
UIWebView keyboard Fastrak iPhone SDK Development 1 06-19-2008 04:21 PM
UIWebView autoscaling Fastrak iPhone SDK Development 0 05-03-2008 10:30 AM

» Advertisements
» Stats
Members: 41,862
Threads: 49,770
Posts: 213,057
Top Poster: BrianSlick (3,139)
Welcome to our newest member, futurevilla216
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:05 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0