【问题标题】:iOS UIWebView flicker issueiOS UIWebView 闪烁问题
【发布时间】:2017-02-01 03:06:58
【问题描述】:

我在同一个屏幕上有一个 UIWebView 和一个滑动手势。当我滑动时,我正在重新加载 webview,因为如果我不这样做,则不会调用 js。

重新加载只能使用一次,我无法再次滑动

当我删除[self.webview reload]swiping 完成后,UIWebView 一直在闪烁。每次都跳起来! 每次刷卡都需要调用js。

我试过这些:

方法一:

when loading webview:
 self.webview.alpha = 0;

- (void)webViewDidFinishLoad:(UIWebView *)webView {

    [UIView beginAnimations:nil context:nil];    
    [UIView setAnimationDuration:0.30];    
    self.webview.alpha = 1;
    [UIView commitAnimations];
}

方法二:

  - (void)webViewDidFinishLoad:(UIWebView *)webView {

    [self.webview setOpaque:NO];
    self.webview.backgroundColor = [UIColor clearColor];
  }

方法三:

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.webview loadHTMLString:@"<html><body style=\"background-color:black;\"></body></html>" baseURL:nil];    

    [self performSelector:@selector(loadWebview) withObject:nil afterDelay:0.1];
}
-(void)loadWebview {

    self.webview.delegate = self;
    self.webview.scrollView.delegate = self;
    self.webview.scrollView.bounces = NO;
    self.webview.scrollView.scrollsToTop = NO;
    [self.view addSubview:self.webview];
    pathToHtml = [[NSBundle mainBundle] pathForResource:@"mypath" ofType:@"html"];
    NSString* appHtml = [NSString stringWithContentsOfFile:pathToHtml encoding:NSUTF8StringEncoding error:nil];
    NSURL *baseURL = [NSURL fileURLWithPath:pathToHtml];

    [self.webview loadHTMLString:appHtml baseURL:baseURL]; 
}

需要帮助!

【问题讨论】:

    标签: javascript ios objective-c uiwebview


    【解决方案1】:

    我发现我的webViewDidFinishLoad 中有这个:

      //Make the page fit to view. THIS IS BAD
        CGRect webviewBound = self. webview.bounds;
        webviewBound.size.height = self. webview.scrollView.contentSize.height;
        self. webview.bounds = webviewBound;
    

    所以我删除了它并添加了:

      [self.webview.scrollView setContentSize: CGSizeMake(self.webview.frame.size.width, self.webview.scrollView.contentSize.height)];
        self.webview.scrollView.delegate = self;
    

    我在viewDidLoad 中添加了这个,因为我有灰色背景:

    //Removes the shadow from the webview i.e., "grey background"
    if ([[self.webview subviews] count] > 0)
    {
        for (UIView* shadowView in [[[self.webview subviews] objectAtIndex:0] subviews])
        {
            [shadowView setHidden:YES];
        }
    
        // unhide the last view so it is visible again because it has the content
        [[[[[self.webview subviews] objectAtIndex:0] subviews] lastObject] setHidden:NO];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-26
      • 2015-01-04
      • 2016-03-06
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多