{"id":1847,"date":"2016-04-15T23:48:35","date_gmt":"2016-04-15T14:48:35","guid":{"rendered":"https:\/\/ecpplus.net\/weblog\/?p=1847"},"modified":"2020-06-26T01:34:48","modified_gmt":"2020-06-25T16:34:48","slug":"wkwebview%e3%81%a7networkactivityindicatorvisible%e3%82%92%e8%a1%a8%e7%a4%ba","status":"publish","type":"post","link":"https:\/\/ecpplus.net\/weblog\/wkwebview%e3%81%a7networkactivityindicatorvisible%e3%82%92%e8%a1%a8%e7%a4%ba\/","title":{"rendered":"WKWebView\u3067networkActivityIndicatorVisible\u3092\u8868\u793a"},"content":{"rendered":"<p>networkActivityIndicatorVisible (iPhone\u306e\u4e0a\u90e8\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u30d0\u30fc\u3067\u8aad\u8fbc\u4e2d\u306b\u3050\u308b\u3050\u308b\u3055\u305b\u308b\u3084\u3064) \u3092\u8868\u793a\u3059\u308b\u65b9\u6cd5\u3002UIWebView \u306f\u3001html,js,css,\u753b\u50cf\u306a\u3069\u306e\u533a\u5225\u304c\u3064\u304b\u306a\u304f\u3066\u7d50\u69cb\u5927\u5909\u3060\u3063\u305f\u3051\u3069\u3001\u305d\u3046\u3044\u3046\u306e\u6c17\u306b\u305b\u305a\u3060\u3044\u3076\u697d\u306b\u5b9f\u88c5\u3067\u304d\u308b\u3002<\/p>\n<p><!--more--><\/p>\n<h1>Controller \u306b\u76f4\u63a5\u66f8\u304f\u30d1\u30bf\u30fc\u30f3<\/h1>\n<h2>KVO\u3092\u76e3\u8996\u3059\u308b<\/h2>\n<p>Controller \u306b\u76f4\u63a5\u66f8\u304f\u5834\u5408\u306f\u3001viewDidLoad \u3068\u304b\u3067\u3001addObserver \u3059\u308b\u3002<\/p>\n<pre><code class=\"language-swift \">var webView : WKWebView!\n<\/code><\/pre>\n<p>\u7684\u306a\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u8a2d\u5b9a\u3057\u3066\u3042\u308b\u3068\u3044\u3046\u524d\u63d0\u3067<\/p>\n<pre><code class=\"language-swift \">webView.addObserver(self, forKeyPath: \"loading\", options: NSKeyValueObservingOptions.New, context: nil)\n<\/code><\/pre>\n<p>\u3068\u3059\u308b\u3002<\/p>\n<p>controller \u304c\u306a\u304f\u306a\u308b\u30bf\u30a4\u30df\u30f3\u30b0\u3067<\/p>\n<pre><code class=\"language-swift \">webView.removeObserver(self, forKeyPath: \"loading\")\n<\/code><\/pre>\n<p>\u3092\u547c\u3076\u306e\u3092\u5fd8\u308c\u305a\u306b\u3002<\/p>\n<h2>KVO\u306e\u5909\u5316\u306b\u30d5\u30c3\u30af\u3055\u305b\u308b<\/h2>\n<pre><code class=\"language-swift \">override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer&lt;Void&gt;) {\n    if keyPath == \"loading\" {\n        UIApplication.sharedApplication().networkActivityIndicatorVisible = webView.loading\n    }\n}\n<\/code><\/pre>\n<p>loading\u72b6\u614b\u304c\u5909\u308f\u308b\u3068\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u547c\u3070\u308c\u308b\u306e\u3067\u3001\u305d\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u3067 <code>webView.loading (BOOL)<\/code> \u304c\u3069\u3046\u306a\u3063\u3066\u3044\u308b\u306e\u304b\u3092\u898b\u308b\u3060\u3051\u3067\u826f\u3044\u3002<\/p>\n<h1>WKWebView \u306e\u30b5\u30d6\u30af\u30e9\u30b9\u3092\u4f5c\u308b\u30d1\u30bf\u30fc\u30f3<\/h1>\n<p>WKWebView \u3092\u4f7f\u3063\u3066\u3001\u7279\u306b\u4f55\u3082\u305b\u305a networkActivityIndicatorVisible \u3060\u3051\u3092\u5909\u3048\u305f\u3044\u5834\u5408\u306f\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30b5\u30d6\u30af\u30e9\u30b9\u3092\u4f5c\u3063\u3066 WKWebView \u3092\u547c\u3093\u3067\u308b\u3068\u3053\u308d\u306b\u7f6e\u304d\u63db\u3048\u308c\u3070\u826f\u3044\u3002<\/p>\n<pre><code class=\"language-swift \">import UIKit\nimport WebKit\n\nclass CustomWebView: WKWebView {\n    init() {\n        super.init(frame: CGRectZero, configuration: WKWebViewConfiguration())\n        self.translatesAutoresizingMaskIntoConstraints = false\n\n        addObserver(self, forKeyPath: \"loading\", options: NSKeyValueObservingOptions.New, context: nil)\n    }\n\n    deinit {\n        removeObserver(self, forKeyPath: \"loading\")\n    }\n\n    override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer&lt;Void&gt;) {\n        if keyPath == \"loading\" {\n            UIApplication.sharedApplication().networkActivityIndicatorVisible = loading\n        }\n    }\n}\n<\/code><\/pre>\n<h2>\u4f7f\u3044\u65b9<\/h2>\n<p>\u5168\u753b\u9762\u8868\u793a\u3067\u3001\u7279\u5b9a\u306eURL\u3092\u8aad\u307f\u8fbc\u3080\u3068\u3044\u3046\u3082\u306e\u3002<\/p>\n<pre><code class=\"language-swift \">let webView = CustomWebView()\n\nview.addSubview(webView)\nview.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(\"V:|[webView]|\", options: NSLayoutFormatOptions(), metrics: nil, views: [\"webView\": webView]))\nview.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(\"H:|[webView]|\", options: NSLayoutFormatOptions(), metrics: nil, views: [\"webView\": webView]))\n\nwebView.loadRequest(NSURL(string : \"https:\/\/memo.ecp.plus\/\"))\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>networkActivityIndicatorVisible (iPhone\u306e\u4e0a\u90e8\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u30d0\u30fc\u3067\u8aad\u8fbc\u4e2d\u306b\u3050\u308b\u3050\u308b\u3055\u305b\u308b\u3084\u3064) \u3092\u8868\u793a\u3059\u308b\u65b9\u6cd5\u3002UIWebView \u306f\u3001html,js,css,\u753b\u50cf\u306a\u3069\u306e\u533a\u5225\u304c\u3064\u304b\u306a\u304f [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1483,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[35],"class_list":["post-1847","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-ios"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"networkActivityIndicatorVisible (iPhone\u306e\u4e0a\u90e8\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u30d0\u30fc\u3067\u8aad\u8fbc\u4e2d\u306b\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"chu\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/ecpplus.net\/weblog\/wkwebview%e3%81%a7networkactivityindicatorvisible%e3%82%92%e8%a1%a8%e7%a4%ba\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"ja_JP\" \/>\n\t\t<meta property=\"og:site_name\" content=\"\u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"WKWebView\u3067networkActivityIndicatorVisible\u3092\u8868\u793a | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta property=\"og:description\" content=\"networkActivityIndicatorVisible (iPhone\u306e\u4e0a\u90e8\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u30d0\u30fc\u3067\u8aad\u8fbc\u4e2d\u306b\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/ecpplus.net\/weblog\/wkwebview%e3%81%a7networkactivityindicatorvisible%e3%82%92%e8%a1%a8%e7%a4%ba\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2013\/03\/new_hero20110308.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2013\/03\/new_hero20110308.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t\t<meta property=\"og:image:height\" content=\"240\" \/>\n\t\t<meta property=\"article:tag\" content=\"development\" \/>\n\t\t<meta property=\"article:tag\" content=\"ios\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2016-04-15T14:48:35+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2020-06-25T16:34:48+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@ecpplus\" \/>\n\t\t<meta name=\"twitter:title\" content=\"WKWebView\u3067networkActivityIndicatorVisible\u3092\u8868\u793a | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta name=\"twitter:description\" content=\"networkActivityIndicatorVisible (iPhone\u306e\u4e0a\u90e8\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u30d0\u30fc\u3067\u8aad\u8fbc\u4e2d\u306b\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@ecpplus\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2013\/03\/new_hero20110308.jpg\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"WKWebView\u3067networkActivityIndicatorVisible\u3092\u8868\u793a | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","description":"networkActivityIndicatorVisible (iPhone\u306e\u4e0a\u90e8\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u30d0\u30fc\u3067\u8aad\u8fbc\u4e2d\u306b","canonical_url":"https:\/\/ecpplus.net\/weblog\/wkwebview%e3%81%a7networkactivityindicatorvisible%e3%82%92%e8%a1%a8%e7%a4%ba\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"ja_JP","og:site_name":"\u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","og:type":"article","og:title":"WKWebView\u3067networkActivityIndicatorVisible\u3092\u8868\u793a | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","og:description":"networkActivityIndicatorVisible (iPhone\u306e\u4e0a\u90e8\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u30d0\u30fc\u3067\u8aad\u8fbc\u4e2d\u306b","og:url":"https:\/\/ecpplus.net\/weblog\/wkwebview%e3%81%a7networkactivityindicatorvisible%e3%82%92%e8%a1%a8%e7%a4%ba\/","og:image":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2013\/03\/new_hero20110308.jpg","og:image:secure_url":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2013\/03\/new_hero20110308.jpg","og:image:width":400,"og:image:height":240,"article:tag":["development","ios"],"article:published_time":"2016-04-15T14:48:35+00:00","article:modified_time":"2020-06-25T16:34:48+00:00","twitter:card":"summary_large_image","twitter:site":"@ecpplus","twitter:title":"WKWebView\u3067networkActivityIndicatorVisible\u3092\u8868\u793a | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","twitter:description":"networkActivityIndicatorVisible (iPhone\u306e\u4e0a\u90e8\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u30d0\u30fc\u3067\u8aad\u8fbc\u4e2d\u306b","twitter:creator":"@ecpplus","twitter:image":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2013\/03\/new_hero20110308.jpg"},"aioseo_meta_data":{"post_id":"1847","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":"","og_description":"","og_object_type":"article","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":"","og_article_tags":"","twitter_use_og":false,"twitter_card":"summary_large_image","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-01-02 15:53:43","updated":"2022-09-29 10:33:51","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/ecpplus.net\/weblog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/ecpplus.net\/weblog\/category\/development\/\" title=\"Development\">Development<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tWKWebView\u3067networkActivityIndicatorVisible\u3092\u8868\u793a\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/ecpplus.net\/weblog"},{"label":"Development","link":"https:\/\/ecpplus.net\/weblog\/category\/development\/"},{"label":"WKWebView\u3067networkActivityIndicatorVisible\u3092\u8868\u793a","link":"https:\/\/ecpplus.net\/weblog\/wkwebview%e3%81%a7networkactivityindicatorvisible%e3%82%92%e8%a1%a8%e7%a4%ba\/"}],"_links":{"self":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/comments?post=1847"}],"version-history":[{"count":2,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1847\/revisions"}],"predecessor-version":[{"id":2858,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1847\/revisions\/2858"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media\/1483"}],"wp:attachment":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media?parent=1847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/categories?post=1847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/tags?post=1847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}