Wkwebview Progress and Title

Source: Internet
Author: User

Wkwebview Progress and Title

Wkwebview's estimatedprogress and title are KVO modes, so you can add monitoring:

    [webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:NULL];    [webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];

How to implement monitoring:

- (void) Observevalueforkeypath: (NSString *) KeyPath Ofobject: (ID)ObjectChange: (nsdictionary *) Change context: (void*) Context {if([KeyPath isequaltostring:@"estimatedprogress"]) {        if(Object==WebView) {[Self.progressview Setalpha:1.0f];            [Self.progressview setProgress:self.currentSubView.webView.estimatedProgress Animated:yes]; if(Self.currentSubView.webView.estimatedProgress >=1.0f) {[UIView animatewithduration:0.3Delay0.3Options:uiviewanimationoptioncurveeaseout animations:^{[Self.progressview setalpha:0.0f]; } Completion:^(BOOL finished) {[Self.progressview setprogress:0.0fAnimated:no];            }]; }        }        Else{[Super Observevalueforkeypath:keypath Ofobject:ObjectChange:change Context:context]; }    }    Else if([KeyPath isequaltostring:@"title"])    {        if(Object==self.webview) {self.title=Self.webView.title; }        Else{[Super Observevalueforkeypath:keypath Ofobject:ObjectChange:change Context:context]; }    }    Else{[Super Observevalueforkeypath:keypath Ofobject:ObjectChange:change Context:context]; }}

The progress here is animated, like Safari's progress effect

It's important to note that when destroying, you must remove the monitoring

        [WebView removeobserver:self Forkeypath:@ "estimatedprogress"];        [WebView removeobserver:self Forkeypath: @" title "];

Wkwebview Progress and Title

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.