开发者

iOS Web app disable offset scrolling

开发者 https://www.devze.com 2023-03-17 22:55 出处:网络
How can I disable the offset scrolling for my webapp? I mean the dark gray area http://i.stack.imgur.com/a3Rt4.png

How can I disable the offset scrolling for my webapp?

I mean the dark gray area http://i.stack.imgur.com/a3Rt4.png

Disable scrolling in an开发者_开发技巧 iPhone web application? I've tried this but it didn't work all the time, it only works sometimes then it suddenly stops and i can scroll again.


document.body.addEventListener('touchmove', function(e){ e.preventDefault(); });

works, but make sure the body has a 100% height of the screen


This completely disables all touch-move events.

<script type="text/javascript">
    function blockMove() {
       event.preventDefault() ;
}
</script>

<body ontouchmove="blockMove()">

It freezes your screen in place, giving it a more native feel. But also disables any scrollable areas. If you want to keep your scrollable areas and still remove the rubber band effect at the top and bottom, see here: http://cubiq.org/iscroll.


The bottom line is that there are a number of ways to achieve this, but none are documented. They all currently rely on searching through subviews of your UIWebView and modifying their properties - all of these subviews are undocumented, so your results may vary. It is certainly not an ideal way to do things, and as you've found out results can be varied. If you can get hold of the scroll view that is contained within the web view (again, undocumented) you can disable the offset scrolling/bouncing - this link may prove helpful:

http://blog.andrewpaulsimmons.com/2010/02/controlling-uiscrollview-in-uiwebview.html

iOS 5 has an official fix for this, but you'd need to ask at devforums.apple.com or read the new documentation, because everything iOS 5 related is still under non-disclosure and can't really be discussed here.


I wrote this solution for allowing scrollable areas but preventing the body from scrolling when they're visible

https://stackoverflow.com/a/18922984/2009533

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号