加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xcode – 如何提高UIWebView的滚动速度?

发布时间:2020-12-14 17:58:58 所属栏目:百科 来源:网络整理
导读:我有一个应用程序在其中一个选项卡上使用UIWebView. 一切都像它应该的那样工作,但视图滚动的速度非常慢!如果我在模拟器中构建它或者如果我在我的iPhone中构建它并不重要,它就是相同的慢速滚动. 如何提高视图的滚动速度?我注意到,一旦手指离开屏幕,它就会停
我有一个应用程序在其中一个选项卡上使用UIWebView.
一切都像它应该的那样工作,但视图滚动的速度非常慢!如果我在模拟器中构建它或者如果我在我的iPhone中构建它并不重要,它就是相同的慢速滚动.
如何提高视图的滚动速度?我注意到,一旦手指离开屏幕,它就会停止滚动,而不是像野生动物园那样保持滚动和减速,这与它有什么关系吗?

这是我的.h文件:

//  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

这是我的.m文件:

//
//  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

解决方法

试试这个:

webView.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal;

注意:iOS 9中存在一个错误,您可能需要解决https://stackoverflow.com/a/32843700/308315问题

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读