簡體   English   中英

如何在uiwebview上提高滾動速度

[英]How to increase scrolling speed on uiwebview

我使用下面的代碼在UIWebview上滾動速度,與以前的滾動方式相比還不錯,但我的克林特並不滿意,他這樣問

滾動仍然感覺僵硬。

webviews.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal;

[webviews loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"site URL"]]];
    webviews.scalesPageToFit =YES;`

有沒有增加滾動速度的選項?

在UIScrollViewDelegate上具有這些屬性

CGPoint lastOffset;
NSTimeInterval lastOffsetCapture;
BOOL isScrollingFast;

然后為您的scrollViewDidScroll使用以下代碼:

- (void) scrollViewDidScroll:(UIScrollView *)scrollView {    
    CGPoint currentOffset = self.currentChannelTableView.contentOffset;
    NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];

    NSTimeInterval timeDiff = currentTime - lastOffsetCapture;
    if(timeDiff > 0.1) {
        CGFloat distance = currentOffset.y - lastOffset.y;
        //The multiply by 10, / 1000 isn't really necessary.......
        CGFloat scrollSpeedNotAbs = (distance * 10) / 1000; //in pixels per millisecond

        CGFloat scrollSpeed = fabsf(scrollSpeedNotAbs);
        if (scrollSpeed > 0.5) {
            isScrollingFast = YES;
            NSLog(@"Fast");
        } else {
            isScrollingFast = NO;
            NSLog(@"Slow");
        }        

        lastOffset = currentOffset;
        lastOffsetCapture = currentTime;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM