{"id":196,"date":"2021-09-23T19:00:00","date_gmt":"2021-09-23T11:00:00","guid":{"rendered":"https:\/\/www.hlzhy.com\/?p=196"},"modified":"2024-04-12T15:34:31","modified_gmt":"2024-04-12T07:34:31","slug":"ios-15-%e9%80%8f%e6%98%8e%e5%af%bc%e8%88%aa%e6%a0%8f%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/www.hlzhy.com\/?p=196","title":{"rendered":"iOS 15 \u900f\u660e\u5bfc\u822a\u680f\u8bbe\u7f6e"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"384\" height=\"384\" src=\"https:\/\/www.hlzhy.com\/wp-content\/uploads\/2021\/09\/IOS_15_logo.png\" alt=\"\" class=\"wp-image-197\" srcset=\"https:\/\/www.hlzhy.com\/wp-content\/uploads\/2021\/09\/IOS_15_logo.png 384w, https:\/\/www.hlzhy.com\/wp-content\/uploads\/2021\/09\/IOS_15_logo-300x300.png 300w, https:\/\/www.hlzhy.com\/wp-content\/uploads\/2021\/09\/IOS_15_logo-150x150.png 150w\" sizes=\"(max-width: 384px) 100vw, 384px\" \/><\/figure><\/div>\n\n\n<p>\u5728iOS 13&nbsp;<code>UINavigationBar<\/code>\u65b0\u589e\u4e86<code>scrollEdgeAppearance<\/code>\u5c5e\u6027\uff0c\u4f46\u5728iOS 14\u53ca\u66f4\u65e9\u7684\u7248\u672c\u4e2d\u6b64\u5c5e\u6027\u53ea\u5e94\u7528\u5728<strong>\u5927\u6807\u9898\u5bfc\u822a\u680f<\/strong>\u4e0a\u3002\u5728iOS 15\u4e2d\u6b64\u5c5e\u6027\u9002\u7528\u4e8e\u6240\u6709\u5bfc\u822a\u680f\u3002<br>\u5bf9\u4e8e<code>scrollEdgeAppearance<\/code>\u5c5e\u6027\u7684\u8bf4\u660e\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>When a navigation controller contains a navigation bar and a scroll view, part of the scroll view\u2019s content appears underneath the navigation bar. If the edge of the scrolled content reaches that bar, UIKit applies the appearance settings in this property.<br>If the value of this property is&nbsp;<code>nil<\/code>, UIKit uses the settings found in the&nbsp;<a href=\"https:\/\/links.jianshu.com\/go?to=https%3A%2F%2Fdeveloper.apple.com%2Fdocumentation%2Fuikit%2Fuinavigationbar%2F3198028-standardappearance\" target=\"_blank\" rel=\"noreferrer noopener\">standard Appearance<\/a>&nbsp;property, modified to use a transparent background. If no navigation controller manages your navigation bar, UIKit ignores this property and uses the standard appearance of the navigation bar.<\/p><\/blockquote>\n\n\n\n<p><code>scrollEdgeAppearance<\/code>\u662f<code>UINavigationBarAppearance<\/code>\u7c7b\u578b\uff0c\u6709\u4e0b\u9762\u51e0\u4e2a\u5c5e\u6027\uff1a<\/p>\n\n\n\n<p>backgroundEffect\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u57fa\u4e8e<code>backgroundColor<\/code>\u6216<code>backgroundImage<\/code>\u7684\u78e8\u7802\u6548\u679c<\/p><\/blockquote>\n\n\n\n<p>backgroundColor\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u80cc\u666f\u8272\uff0c\u5728<code>backgroundImage<\/code>\u4e4b\u4e0b<\/p><\/blockquote>\n\n\n\n<p>backgroundImage\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u80cc\u666f\u56fe\u7247<\/p><\/blockquote>\n\n\n\n<p>backgroundImageContentMode\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u6e32\u67d3<code>backgroundImage<\/code>\u65f6\u4f7f\u7528\u7684\u5185\u5bb9\u6a21\u5f0f\u3002 \u9ed8\u8ba4\u4e3a<code>UIViewContentModeScaleToFill<\/code>\u3002<\/p><\/blockquote>\n\n\n\n<p>shadowColor\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u9634\u5f71\u989c\u8272\uff08\u5e95\u90e8\u5206\u5272\u7ebf\uff09\uff0c\u5f53<code>shadowImage<\/code>\u4e3a<code>nil<\/code>\u65f6\uff0c\u76f4\u63a5\u4f7f\u7528\u6b64\u989c\u8272\u4e3a\u9634\u5f71\u8272\u3002\u5982\u679c\u6b64\u5c5e\u6027\u4e3a<code>nil<\/code>\u6216<code>clearColor<\/code>\uff08\u9700\u8981\u663e\u5f0f\u8bbe\u7f6e\uff09\uff0c\u5219\u4e0d\u663e\u793a\u9634\u5f71\u3002<\/p><p>\u5982\u679c<code>shadowImage<\/code>\u5305\u542b template \u56fe\u50cf\uff0c\u5219\u4f7f\u7528\u8be5\u56fe\u50cf\u4f5c\u4e3a\u9634\u5f71\u5e76\u4f7f\u7528\u6b64\u5c5e\u6027\u4e2d\u7684\u503c\u5bf9\u5176\u8fdb\u884c\u7740\u8272\u3002\u5982\u679c\u6b64\u5c5e\u6027\u4e3a<code>nil<\/code>\u6216<code>clearColor<\/code>\uff08\u9700\u8981\u663e\u5f0f\u8bbe\u7f6e\uff09\uff0c\u5219\u4e0d\u663e\u793a\u9634\u5f71\u3002<br>\u4f46\u662f\uff0c\u5982\u679c<code>shadowImage<\/code>\u4e0d\u5305\u542b template \u56fe\u50cf\uff0c\u5219\u6b64\u5c5e\u6027\u65e0\u6548\u3002<\/p><\/blockquote>\n\n\n\n<p>shadowImage\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u9634\u5f71\u56fe\u7247\u3002<br><em>template\u56fe\u50cf:&nbsp;<code>[img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]<\/code><\/em><\/p><\/blockquote>\n\n\n\n<h4 class=\"wp-block-heading\">\u793a\u4f8b\u4ee3\u7801\uff1a<\/h4>\n\n\n\n<ul><li>\u4e0d\u900f\u660e\u5bfc\u822a\u680f\uff1a<\/li><\/ul>\n\n\n\n<p><em><\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \/\/navigation\u6807\u9898\u6587\u5b57\u989c\u8272\n    NSDictionary *dic = @{NSForegroundColorAttributeName : &#91;UIColor blackColor],\n                          NSFontAttributeName : &#91;UIFont systemFontOfSize:18 weight:UIFontWeightMedium]};\n    if (@available(iOS 15.0, *)) {\n        UINavigationBarAppearance *barApp = &#91;UINavigationBarAppearance new];\n        barApp.backgroundColor = &#91;UIColor whiteColor];\n        barApp.shadowColor = &#91;UIColor whiteColor];\n        barApp.titleTextAttributes = dic;\n        self.navigationController.navigationBar.scrollEdgeAppearance = barApp;\n        self.navigationController.navigationBar.standardAppearance = barApp;\n    }else{\n        \/\/\u80cc\u666f\u8272\n        self.navigationController.navigationBar.barTintColor = &#91;UIColor whiteColor];\n        self.navigationController.navigationBar.titleTextAttributes = dic;\n        &#91;self.navigationBar setShadowImage:&#91;UIImage new]];\n        &#91;self.navigationBar setBackgroundImage:&#91;UIImage new] forBarMetrics:UIBarMetricsDefault];\n    }\n    \/\/\u4e0d\u900f\u660e\n    self.navigationController.navigationBar.translucent = NO;\n    \/\/navigation\u63a7\u4ef6\u989c\u8272\n    self.navigationController.navigationBar.tintColor = &#91;UIColor blackColor];<\/code><\/pre>\n\n\n\n<ul><li>\u900f\u660e\u5bfc\u822a\u680f:<\/li><\/ul>\n\n\n\n<p><del>\u56e0\u4e3a<code>scrollEdgeAppearance = nil<\/code>\uff0c\u5f53\u524d\u5982\u679c\u6709<code>ScrollView<\/code>\uff0c\u5f53<code>ScrollView<\/code>\u5411\u4e0a\u6eda\u52a8\u65f6<code>scrollEdgeAppearance<\/code>\u4f1a\u9ed8\u8ba4\u4f7f\u7528<code>standardAppearance<\/code>\u3002\u56e0\u6b64<code>backgroundEffect<\/code>\u548c<code>shadowColor<\/code>\u4e5f\u8981\u663e\u5f0f\u8bbe\u7f6e\u4e3a<code>nil<\/code>\uff0c\u9632\u6b62<code>backgroundEffect<\/code>\u3001<code>shadowColor<\/code>\u51fa\u73b0\u53d8\u6210\u6709\u989c\u8272\u7684\u3002<\/del>&nbsp;\uff08\u66f4\u65b0Xcode13.4.1\u540e\u548c\u4e4b\u524d\u4f3c\u4e4e\u4e0d\u4e00\u6837\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \/\/navigation\u6807\u9898\u6587\u5b57\u989c\u8272\n    NSDictionary *dic = @{NSForegroundColorAttributeName : &#91;UIColor whiteColor],\n                          NSFontAttributeName : &#91;UIFont systemFontOfSize:18]};\n    if (@available(iOS 15.0, *)) {\n        UINavigationBarAppearance *barApp = &#91;UINavigationBarAppearance new];\n        barApp.backgroundColor = &#91;UIColor clearColor];\n        barApp.titleTextAttributes = dic;   \n        barApp.backgroundEffect = nil;\n        barApp.shadowColor = nil;\n        self.navigationController.navigationBar.scrollEdgeAppearance = barApp;\n        self.navigationController.navigationBar.standardAppearance = barApp;\n    }else{\n        self.navigationController.navigationBar.titleTextAttributes = dic;\n        &#91;self.navigationBar setShadowImage:&#91;UIImage new]];\n        &#91;self.navigationBar setBackgroundImage:&#91;UIImage new] forBarMetrics:UIBarMetricsDefault];\n    }\n    \/\/\u900f\u660e\n    self.navigationController.navigationBar.translucent = YES;\n    \/\/navigation\u63a7\u4ef6\u989c\u8272\n    self.navigationController.navigationBar.tintColor = &#91;UIColor whiteColor];\n<\/code><\/pre>\n\n\n\n<ul><li>\u900f\u660e\u5bfc\u822a\u680f\u65f6\u52a8\u6001\u4fee\u6539\u989c\u8272:<\/li><\/ul>\n\n\n\n<p><em><\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-(Void)setNavigationBarBackgroundColor:(UIColor *)color {\n        if (@available(iOS 15.0, *)) {\n            self.navigationController.navigationBar.standardAppearance.backgroundColor = color\n            self.navigationController.navigationBar.scrollEdgeAppearance.backgroundColor = color\n        }else{\n            self.navigationController.navigationBar.barTintColor = color\n        }\n    }<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>2024\u5e7404\u670812\u65e5<\/p>\n\n\n\n<p><code>push<\/code>&nbsp;\u65f6\u8bbe\u7f6e&nbsp;<code>backgroundColor = .clear<\/code>\u6ca1\u6709\u8fc7\u6e21\u52a8\u753b\uff0c\u53ef\u4ee5\u6539\u53d8\u989c\u8272\u900f\u660e\u5ea6<code>alpha<\/code>\u6765\u5b9e\u73b0\u3002\u6bd4\u5982\u53ef\u4ee5\u5199\u6210<code>backgroundColor = UIColor(white: 1, alpha: 0)<\/code><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>\u5728iOS 13&nbsp;UINavigationBar\u65b0\u589e\u4e86scrollEdgeAppearance\u5c5e\u6027\uff0c\u4f46\u5728iOS 14\u53ca\u66f4\u65e9\u7684\u7248\u672c\u4e2d\u6b64 &hellip; <a href=\"https:\/\/www.hlzhy.com\/?p=196\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">iOS 15 \u900f\u660e\u5bfc\u822a\u680f\u8bbe\u7f6e<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4],"_links":{"self":[{"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=\/wp\/v2\/posts\/196"}],"collection":[{"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=196"}],"version-history":[{"count":6,"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=\/wp\/v2\/posts\/196\/revisions"}],"predecessor-version":[{"id":255,"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=\/wp\/v2\/posts\/196\/revisions\/255"}],"wp:attachment":[{"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hlzhy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}