iOS-UIWebview相關

1.獲取webview標題

self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];


2.獲取webview實際高度

NSInteger htmlheight = [[self.showWebView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] integerValue];


3.監聽webview contentofset

[_webView.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];


- (void)observeValueForKeyPath:(nullable NSString *)keyPath ofObject:(nullable id)object change:(nullable NSDictionary<NSString*, id> *)change context:(nullable void *)context

{

    if ([keyPath isEqualToString:@"contentOffset"])

    {

        CGFloat y = _webView.scrollView.contentOffset.y;

        if (y>=0 && y<=64) {

            CGFloat nav_alpha = y/64;

            NSLog(@"透明度%f",nav_alpha);

            self.navBar.alpha = nav_alpha;

        }else if(y>64){

            self.navBar.alpha = 1.0;

        }else{

            self.navBar.alpha = 0.0;

        }

    }

}




發佈了28 篇原創文章 · 獲贊 2 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章