{"id":4728,"date":"2017-12-09T22:23:23","date_gmt":"2017-12-09T13:23:23","guid":{"rendered":"https:\/\/ukaapple.selfip.com\/support\/?p=4728"},"modified":"2017-12-10T10:36:34","modified_gmt":"2017-12-10T01:36:34","slug":"original_app_57","status":"publish","type":"post","link":"https:\/\/minnano.app\/support\/2017\/12\/09\/original_app_57\/","title":{"rendered":"\u72ec\u5275\u30a2\u30d7\u30ea\u958b\u767a\u65e5\u8a18 57\u65e5\u76ee iPhoneX\u5b8c\u5168\u5168\u9762\u30ac\u30ef\u30a2\u30d7\u30ea"},"content":{"rendered":"<p>\u524d\u56de\u307e\u3067\u3067\u30d7\u30ed\u30b0\u30ec\u30b9\u30d0\u30fc\u3092\u542b\u3081\u305fWebView\u306e\u30ac\u30ef\u30a2\u30d7\u30ea\u306e\u57fa\u672c\u7684\u306a\u90e8\u5206\u3092\u5b8c\u6210\u3057\u305f\u3064\u3082\u308a\u3060\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3088\u304f\u78ba\u8a8d\u3057\u305f\u3068\u3053\u308d\u3001iPhoneX\u3067\u753b\u9762\u4e0b\u306b\u308f\u305a\u304b\u306bWeb\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u306a\u3044\u9699\u9593\u304c\u51fa\u6765\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u539f\u56e0\u3092\u8abf\u3079\u307e\u304f\u3063\u305f\u3068\u3053\u308d\u3001\u3069\u3046\u3084\u3089contentInset\u3068\u3044\u3046\u3001\u9818\u57df\u5185\u306b\u30b9\u30da\u30fc\u30b9\u3092\u81ea\u52d5\u3067\u5dee\u3057\u8fbc\u3080\u51e6\u7406\u304c\u5b58\u5728\u3057\u305f\u3088\u3046\u3067\u3059\u3002\u305d\u3053\u3067\u3001\u305d\u306e\u9818\u57df\u3092\u53d6\u308b\u3053\u3068\u3067\u672c\u5f53\u306e\u672c\u5f53\u306b\u3001iPhoneX\u306e\u9685\u304b\u3089\u9685\u307e\u3067\u5b8c\u5168\u306a\u5168\u9762\u8868\u793a\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<pre><code>\r\nimport UIKit\r\nimport WebKit\r\n\r\nclass ViewController: UIViewController {\r\n\r\n    private var _webView : WKWebView!\r\n    private var _hideStatusBar : Bool = false\r\n    private var _iPhoneX_Header : CGFloat = 0\r\n    private var _progressView: UIProgressView!\r\n    \r\n    func iPhoneX() -> Bool {\r\n        guard #available(iOS 11.0, *) else {\r\n            return false\r\n        }\r\n        return UIApplication.shared.windows[0].safeAreaInsets != UIEdgeInsets.zero\r\n    }\r\n    \r\n    override func viewDidLoad() {\r\n        super.viewDidLoad()\r\n        \/\/ Do any additional setup after loading the view, typically from a nib.\r\n        \/\/ \u30b9\u30c6\u30fc\u30bf\u30b9\u30d0\u30fc\u306e\u9ad8\u3055\u3092\u53d6\u5f97\r\n        _iPhoneX_Header = iPhoneX() ? UIApplication.shared.statusBarFrame.size.height : 0\r\n        \/\/ WKWebView\u3092\u4f4d\u7f6e\u6307\u5b9a\u3057\u3066\u8868\u793a\r\n        let webC = WKWebViewConfiguration()\r\n        _webView = WKWebView(frame:CGRect(x:0, y: -_iPhoneX_Header, width:self.view.bounds.size.width, height:self.view.bounds.size.height + _iPhoneX_Header), configuration: webC)\r\n        \/\/_webView.scrollView.contentInsetAdjustmentBehavior = .always\r\n        \/\/ \u30b8\u30a7\u30b9\u30c1\u30e3\u30fc(\u30d5\u30ea\u30c3\u30af)\u306b\u3088\u308b \u9032\u3080 \u3084 \u623b\u308b \u3092\u8a31\u53ef\r\n        _webView.allowsBackForwardNavigationGestures = true\r\n        \/\/ WebView\u306e\u8aad\u8fbc\u76e3\u8996\r\n        _webView.addObserver(self, forKeyPath:\"estimatedProgress\", options:.new, context:nil)\r\n        \/\/ \u30b9\u30c6\u30fc\u30bf\u30b9\u30d0\u30fc\u306e\u975e\u8868\u793a \u203b\u30b9\u30c6\u30fc\u30bf\u30b9\u30d0\u30fc\u306e\u9ad8\u3055\u3092\u53d6\u5f97\u3059\u308b\u524d\u306b\u975e\u8868\u793a\u306b\u3059\u308b\u3068\u3001\u30b9\u30c6\u30fc\u30bf\u30b9\u30d0\u30fc\u306e\u9ad8\u3055\u304c\u53d6\u5f97\u3067\u304d\u306a\u3044\r\n        _hideStatusBar = true\r\n        self.setNeedsStatusBarAppearanceUpdate()\r\n        \/\/ \u30c6\u30ad\u30b9\u30c8\u6f2b\u753b\u8aad\u307f\u8fbc\u307f\r\n        let url : URL = URL(string: \"https:\/\/minnano.app\/textmanga\/\")!\r\n        let request : URLRequest = URLRequest(url: url)\r\n        _webView.load(request)\r\n        self.view.addSubview(_webView)\r\n        \/\/ ProgressView\r\n        _progressView = UIProgressView(frame: CGRect(x:0, y:0, width:self.view.bounds.size.width * 2, height:4))\r\n        _progressView.layer.position = CGPoint(x:0, y:self.view.bounds.size.height - 1)\r\n        _progressView.transform = CGAffineTransform(scaleX: 1.0, y: 2.0)\r\n        _progressView.progressTintColor = UIColor.green\r\n        _progressView.trackTintColor = UIColor.orange\r\n        self.view.addSubview(_progressView)\r\n        \/\/ \u56de\u8ee2\u6642\u306e\u901a\u77e5\r\n        NotificationCenter.default.addObserver(self, selector: #selector(ViewController.orientationChange(notification:)), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)\r\n    }\r\n    deinit {\r\n        _webView?.removeObserver(self, forKeyPath: \"estimatedProgress\")\r\n    }\r\n    \r\n    @objc\r\n    private func orientationChange(notification: NSNotification) {\r\n        let portrait : Bool = UIInterfaceOrientationIsPortrait(UIApplication.shared.statusBarOrientation)\r\n        \/\/ WebView\u306e\u8868\u793a\u8abf\u6574\r\n        _webView.frame.origin = CGPoint(x:portrait ? 0 : -_iPhoneX_Header, y:portrait ? -_iPhoneX_Header : 0)\r\n        _webView.frame.size = CGSize(width:self.view.bounds.size.width + (portrait ? 0 : _iPhoneX_Header * 2), height:self.view.bounds.size.height + (portrait ? _iPhoneX_Header : 0))\r\n        _webView.scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: portrait ? -_iPhoneX_Header * 4 \/ 5 : -_iPhoneX_Header \/ 2, right: 0)\r\n        \/\/_webView.scrollView.contentInset = UIEdgeInsets(top: portrait ? _iPhoneX_Header : 0,\r\n        \/\/                                                left: portrait ? 0 : _iPhoneX_Header,\r\n        \/\/                                                bottom: 0,\r\n        \/\/                                                right: portrait ? 0 : _iPhoneX_Header)\r\n        \/\/ \u30d7\u30ed\u30b0\u30ec\u30b9\u30d0\u30fc\u306e\u8868\u793a\u8abf\u6574\r\n        _progressView.frame.origin = CGPoint(x: 0, y: 0)\r\n        _progressView.frame.size = CGSize(width:self.view.bounds.size.width * 2, height:4)\r\n        _progressView.layer.position = CGPoint(x:0, y:self.view.bounds.size.height - 1)\r\n    }\r\n    \r\n    \/\/ \u30b9\u30c6\u30fc\u30bf\u30b9\u30d0\u30fc\u306e\u975e\u8868\u793a\r\n    override var prefersStatusBarHidden: Bool {\r\n        return _hideStatusBar\r\n    }\r\n    \r\n    \/\/ WebView\u306e\u76e3\u8996\r\n    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {\r\n        if(\"estimatedProgress\" == keyPath){\r\n            if(_progressView != nil){\r\n                \/\/ \u66f4\u65b0\r\n                let progress : Float = Float(_webView.estimatedProgress)\r\n                _progressView.setProgress(progress < 1.0 ? progress : 0.0, animated: progress < 1.0)\r\n                _progressView.alpha = progress < 1.0 ? 1.0 : 0.0  \/\/ \u8aad\u307f\u8fbc\u307f\u304c\u5b8c\u4e86\u3057\u305f\u3089\u975e\u8868\u793a\u306b\r\n            }\r\n        }\r\n    }\r\n    \r\n    override func didReceiveMemoryWarning() {\r\n        super.didReceiveMemoryWarning()\r\n        \/\/ Dispose of any resources that can be recreated.\r\n    }\r\n\r\n}\r\n<\/code><\/pre>\n<p>\u4e0b\u8a18\u306f\u4e0a\u306e\u30b3\u30fc\u30c9\u306econtentInset\u51e6\u7406\u90e8\u5206\u306e\u629c\u7c8b\u3067\u3059\u3002 UIEdgeInsets\u3067\u4f59\u767d\u3092\u8abf\u6574\u3057\u3066\u3044\u307e\u3059\u30024 \/ 5 \u3068\u304b 1 \/ 2 \u306f\u3001\u3069\u3046\u3057\u3066\u305d\u3046\u306a\u308b\u306e\u304b\u306f\u308f\u304b\u3089\u306a\u3044\u306e\u3067\u3059\u304c\u3001\u30d4\u30c3\u30bf\u30ea\u753b\u9762\u7aef\u307e\u3067Web\u304c\u8868\u793a\u3055\u308c\u308b\u5024\u3067\u3059\u3002<\/p>\n<p style=\"font-size:xx-large\">\u8ab0\u304b\u3069\u3046\u3057\u3066\u3053\u3046\u306a\u308b\u306e\u304b\u6559\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><code>\r\n_webView.frame.origin = CGPoint(x:portrait ? 0 : -_iPhoneX_Header, y:portrait ? -_iPhoneX_Header : 0)\r\n        _webView.frame.size = CGSize(width:self.view.bounds.size.width + (portrait ? 0 : _iPhoneX_Header * 2), height:self.view.bounds.size.height + (portrait ? _iPhoneX_Header : 0))\r\n        _webView.scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: portrait ? -_iPhoneX_Header * 4 \/ 5 : -_iPhoneX_Header \/ 2, right: 0)\r\n<\/code><\/pre>\n<p>\u3061\u3087\u30fc\u3059\u3063\u304d\u308a\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u307e\u3067\u3067\u30d7\u30ed\u30b0\u30ec\u30b9\u30d0\u30fc\u3092\u542b\u3081\u305fWebView\u306e\u30ac\u30ef\u30a2\u30d7\u30ea\u306e\u57fa\u672c\u7684\u306a\u90e8\u5206\u3092\u5b8c\u6210\u3057\u305f\u3064\u3082\u308a\u3060\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3088\u304f\u78ba\u8a8d\u3057\u305f\u3068\u3053\u308d\u3001iPhoneX\u3067\u753b\u9762\u4e0b\u306b\u308f\u305a\u304b\u306bWeb\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u306a\u3044\u9699\u9593\u304c\u51fa\u6765\u3066\u3044\u307e\u3057\u305f\u3002 \u539f\u56e0\u3092\u8abf\u3079\u307e\u304f &hellip; <a href=\"https:\/\/minnano.app\/support\/2017\/12\/09\/original_app_57\/\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">\u72ec\u5275\u30a2\u30d7\u30ea\u958b\u767a\u65e5\u8a18 57\u65e5\u76ee iPhoneX\u5b8c\u5168\u5168\u9762\u30ac\u30ef\u30a2\u30d7\u30ea<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-4728","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/minnano.app\/support\/wp-json\/wp\/v2\/posts\/4728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/minnano.app\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/minnano.app\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/minnano.app\/support\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/minnano.app\/support\/wp-json\/wp\/v2\/comments?post=4728"}],"version-history":[{"count":4,"href":"https:\/\/minnano.app\/support\/wp-json\/wp\/v2\/posts\/4728\/revisions"}],"predecessor-version":[{"id":4732,"href":"https:\/\/minnano.app\/support\/wp-json\/wp\/v2\/posts\/4728\/revisions\/4732"}],"wp:attachment":[{"href":"https:\/\/minnano.app\/support\/wp-json\/wp\/v2\/media?parent=4728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/minnano.app\/support\/wp-json\/wp\/v2\/categories?post=4728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/minnano.app\/support\/wp-json\/wp\/v2\/tags?post=4728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}