 |
 |
|
 |
05-01-2008, 11:37 AM
|
#1 (permalink)
|
|
New Member
Join Date: Apr 2008
Location: Onomatopoeia, Lugubriousylvania
Posts: 225
|
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?
|
|
|
05-01-2008, 12:17 PM
|
#2 (permalink)
|
|
New Member
Join Date: Apr 2008
Posts: 802
|
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.
|
|
|
05-01-2008, 12:49 PM
|
#3 (permalink)
|
|
New Member
Join Date: Apr 2008
Location: Onomatopoeia, Lugubriousylvania
Posts: 225
|
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).
|
|
|
05-01-2008, 01:59 PM
|
#4 (permalink)
|
|
Registered Member
Join Date: Apr 2008
Posts: 57
|
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.
|
|
|
05-01-2008, 03:05 PM
|
#5 (permalink)
|
|
New Member
Join Date: Apr 2008
Posts: 802
|
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.
|
|
|
07-25-2008, 12:22 PM
|
#6 (permalink)
|
|
Not So Junior Member
Join Date: Jul 2008
Posts: 4
|
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.
|
|
|
07-25-2008, 11:33 PM
|
#7 (permalink)
|
|
Senior Member
Join Date: Jul 2008
Posts: 146
|
Quote:
Originally Posted by bonehead
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.
|
|
|
08-07-2008, 01:06 AM
|
#8 (permalink)
|
|
Registered Member
Join Date: Apr 2008
Posts: 57
|
MaCeXpErTo,
Can you give an example on how to use the @property(nonatomic) BOOL bounces to stop the UIWebView from bouncing?
Thanks
|
|
|
09-11-2008, 11:19 AM
|
#9 (permalink)
|
|
Registered Member
Join Date: Aug 2008
Posts: 169
|
Quote:
Originally Posted by brianr
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.
|
|
|
12-08-2008, 11:04 PM
|
#10 (permalink)
|
|
Registered Member
Join Date: May 2008
Location: New York City, NY
Posts: 177
|
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
|
|
|
04-25-2009, 05:41 PM
|
#11 (permalink)
|
|
New Member
Join Date: Jan 2009
Posts: 2
|
Quote:
Originally Posted by markww
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.
|
|
|
04-25-2009, 09:08 PM
|
#12 (permalink)
|
|
New Member
Join Date: Jan 2009
Posts: 2
|
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
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.
|
|
|
|
05-02-2009, 02:12 AM
|
#13 (permalink)
|
|
New Member
Join Date: Apr 2009
Posts: 2
|
This works...
Thanks for the info.
Quote:
Originally Posted by coolblade
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
|
|
|
|
07-15-2009, 12:57 PM
|
#14 (permalink)
|
|
FlipConversionDesign
Join Date: Aug 2008
Location: Orangeville, Ontario
Posts: 83
|
Quote:
Originally Posted by rajeshgautam
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 =/
|
|
|
07-17-2009, 08:20 PM
|
#15 (permalink)
|
|
Registered Member
Join Date: Jan 2009
Location: NY, USA
Posts: 275
|
Quote:
Originally Posted by rajeshgautam
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?
|
|
|
11-23-2009, 08:23 PM
|
#16 (permalink)
|
|
Registered Member
Join Date: Jan 2009
Location: NY, USA
Posts: 275
|
FYI: People are getting rejected for this
From Apple email:
"The non-public API that is included in your applications is setAllowsRubberBanding"
|
|
|
12-01-2009, 07:58 PM
|
#17 (permalink)
|
|
Registered Member
Join Date: Dec 2009
Posts: 2
|
Allow scroll only when necessary
Quote:
Originally Posted by krye
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>
|
|
|
12-01-2009, 11:20 PM
|
#18 (permalink)
|
|
Registered Member
Join Date: Jan 2009
Location: NY, USA
Posts: 275
|
Quote:
Originally Posted by V42
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.
|
|
|
12-02-2009, 05:38 AM
|
#19 (permalink)
|
|
Registered Member
Join Date: Jul 2009
Location: Los Angeles
Posts: 238
|
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.
|
|
|
12-02-2009, 01:43 PM
|
#20 (permalink)
|
|
Registered Member
Join Date: Dec 2009
Posts: 2
|
Scrolling fix for OS v2.2.1
Quote:
Originally Posted by V42
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.
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 432 |
| 40 members and 392 guests |
| AdamSubach, aderrington, anubhab123, benoitr007, BrianSlick, caseysackett, Danneman, dev123, ErichGS, futurevilla216, Gambit, GreatWizard, gustavo7sexton, gw1921, HemiMG, HowEver, iSDK, Jeremy1026, joelhull, lifeCoder45, mattiahalter, mcapraro, melodizzzy, mriphoneman, newchucky, Ovidius, Piequanna, qilin, Racker, rendezvouscp, riq, Sega dude, socals, themathminister, timle8n1, tinrocket, Whitehk, ZunePod |
| Most users ever online was 965, 06-30-2010 at 04:26 AM. |
» Stats |
Members: 41,862
Threads: 49,770
Posts: 213,057
Top Poster: BrianSlick (3,139)
|
| Welcome to our newest member, futurevilla216 |
|