iPhone开发:在UIWebView中提高滚动速度?

tho*_*max 7 iphone cocoa-touch scroll uiwebview

我有一个应用程序,我在UIWebView中呈现本地HTML文件.但是,文件有时很大,并且使用默认滚动速度到达您想要的位置需要很长时间.有没有办法提高UIWebView的垂直滚动速度?

Bru*_*ado 23

在iOS 5中,我们可以访问该scrollView属性UIWebView.

如果您的目标是iOS 5+,则可以直接致电:

webView.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal;
Run Code Online (Sandbox Code Playgroud)


Quo*_*ion 7

找到UIWebView的子视图,它是一个UIScrollView,然后将decelerationRate设置为UIScrollViewDecelerationRateNormal.这使得UIWebView与普通的UIScrollView一样快.

在iOS 4/5中,我们可以简单地使用UIWebView的最后一个子视图.

UIScrollView *scroll = [webView.subviews lastObject];
if ([scroll isKindOfClass:[UIScrollView class]]) {
    scroll.decelerationRate = UIScrollViewDecelerationRateNormal;
}
Run Code Online (Sandbox Code Playgroud)

UIWebView的UIScrollView 的默认减速率为0.989324,而UIScrollViewDecelerationRateFast为0.99,UIScrollViewDecelerationRateNormal为0.998.

此方法不使用任何私有API.