iPhone HTML5 应用滚动问题 [英] iPhone HTML5 App Scrolling Question

查看:31
本文介绍了iPhone HTML5 应用滚动问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是否可行,也不知道如何通过 Google 找到它,但您可以添加:

I don't know if this is even possible or what to Google to find it, but like you can add:

<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>

它会让你不能左右滚动,只能上下滚动.有没有办法让它在到达终点时不会产生过度滚动效果,而是继续滚动然后又弹出?就像 Cocoa 应用程序一样,我注意到过度滚动"有时它们具有相同的背景颜色,所以它看起来不像 Safari 的或者根本不这样做?

And it will make it so you can't scroll side to side, only up and down. Is there a way to make it so it doesn't do that overscroll effect when you reach the end but keep scrolling and then it pops back? Like Cocoa apps ive noticed that "overscroll" sometimes they have the same background color so it doesn't look like Safari's or it just doesn't do it at all?

推荐答案

您所说的过度滚动称为反弹.不幸的是,没有记录的方法来关闭 UIWebView 中的反弹.您可以查看 UIScrollView 以获取与反弹相关的方法.UIWebView 拥有 UIScrollView 但不公开它.

What you are calling overscroll is called bounce. Unfortunately there is not a documented way to turn off bounce in a UIWebView. You can look at UIScrollView for bounce related methods. A UIWebView owns a UIScrollView but does not expose it.

为了防止水平滚动,您只需确保您的网页适合视口.不适合的一个常见原因是当主体边距不为零时 100% 宽度的项目.

To prevent horizontal scrolling, you just have to ensure that your web page fits within the viewport. One common cause of not fitting is a 100% width item when the body margin is not zero.

您可以通过向文档添加触摸事件处理程序并在事件上调用 preventDefault 来完全防止滚动和弹跳.如果您的网页完全适合视口,这将有效地禁用反弹.

You can completely prevent scrolling and bounce by adding touch event handlers to the document and calling preventDefault on the event. This will effectively disable bounce if your web page completely fits in the viewport.

function stopScrolling( touchEvent ) { touchEvent.preventDefault(); }
document.addEventListener( 'touchstart' , stopScrolling , false );
document.addEventListener( 'touchmove' , stopScrolling , false );

UIWebView 在 Objective-C 方面大多是私有的,但从 javascript 方面相当容易访问.你可以注入javascript,如果您无法控制正在加载的内容.

UIWebView is mostly private from the Objective-C side but fairly accessible from the javascript side. You can inject javascript if you do not control the content being loaded.

这篇关于iPhone HTML5 应用滚动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆