Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase scroll speed of UIWebView?

I have an app that uses a UIWebView on one of it's tabs. Everything is working like it should, but the speed that the view is scrolling is extremely slow! It doesn't matter if I build it in the simulator or if I build it in my iPhone, it's the same slow scroll. How can I increase the scrolling speed of the view? I've noticed that it will stop scrolling as soon as the finger leaves the screen, instead of keep scrolling and decelerate like in safari, does this have anything to do with it?

The is my .h file:

//  FirstViewController_SE.h
//  WebApp
//
//  Created by Camilla Fröberg on 2012-03-29.
//  Copyright (c) 2012 SafeLine Sweden AB. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface FirstViewController_SE : UIViewController<UIWebViewDelegate> {

IBOutlet UIWebView *webDisplay_SE;
    UIBarButtonItem* mBack;
    UINavigationItem* back;

}

@property(nonatomic,retain) UIWebView *webDisplay_SE;
@property (nonatomic, retain) IBOutlet UIBarButtonItem* back;

- (void)updateButtons;


@end

And this is my .m file:

//
//  FirstViewController_SE.m
//  WebApp
//
//  Created by Camilla Fröberg on 2012-03-29.
//  Copyright (c) 2012 SafeLine Sweden AB. All rights reserved.
//

#import "FirstViewController_SE.h"

@interface FirstViewController_SE ()


@end

@implementation FirstViewController_SE;
@synthesize webDisplay_SE;
@synthesize back = mBack;

#pragma mark - View lifecycle


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    self.webDisplay_SE.delegate = self;


    NSString *urlAddress = @"http://www.safeline.eu/mobile/se/product";

    //Create a URL object.
    NSURL *url = [NSURL URLWithString:urlAddress];

    //URL Requst Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    //Load the request in the UIWebView.
    [webDisplay_SE loadRequest:requestObj];

    [self updateButtons];   
}


- (void)viewDidUnload {
    self.back = nil;
    [super viewDidUnload];

    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}


- (void)updateButtons
{
    self.back.enabled = self.webDisplay_SE.canGoBack;
}



- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}


- (BOOL)webDisplay_SE:(UIWebView *)webDisplay_SE shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    return YES;
}



- (void)webViewDidStartLoad:(UIWebView *)webDisplay_SE
{
    [self updateButtons];
}

- (void)webViewDidFinishLoad:(UIWebView *)webDisplay_SE
{
    [self updateButtons];
}




@end
like image 753
Camilla Avatar asked Apr 03 '12 07:04

Camilla


1 Answers

Try this:

webView.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal;

Note: there's a bug in iOS 9 that you may need to workaround https://stackoverflow.com/a/32843700/308315

like image 163
thomax Avatar answered Nov 15 '22 07:11

thomax