iPhone dev: Increase scroll speed in UIWebView?

后端 未结 5 1180
滥情空心
滥情空心 2021-02-09 04:41

I have an app in which I render local HTML files in a UIWebView. The files, however, are sometimes large, and getting to where you want takes a long time with the default scroll

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-09 05:20

    Find a subview of UIWebView which is a UIScrollView, then set decelerationRate to UIScrollViewDecelerationRateNormal. This makes the UIWebView as fast as an ordinary UIScrollView.

    In iOS 4/5, we can simply use the last subview of UIWebView.

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

    The default decelerationRate of UIWebView's UIScrollView is 0.989324, while UIScrollViewDecelerationRateFast is 0.99, and UIScrollViewDecelerationRateNormal is 0.998.

    This method doesn't use any private API.

提交回复
热议问题