簡體   English   中英

iOS UIWebView閃爍問題

[英]iOS UIWebView flicker issue

我在同一屏幕上有一個UIWebView和一個滑動手勢。 刷卡時,我正在重新加載Webview,因為如果不這樣做,就不會調用js。

重新加載僅一次, 我無法再次刷卡

當我刪除[self.webview reload]滑動就可以了,但是UIWebView一直閃爍。 每次都會跳起來! 每次滑動時,我都需要致電js。

我嘗試了這些:

方法1:

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];
}

方法2:

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

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

方法3:

- (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]; 
}

需要幫忙!

我發現我的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];
}

暫無
暫無

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

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