{"id":6816,"date":"2025-06-02T13:20:03","date_gmt":"2025-06-05T05:44:03","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6816"},"modified":"2025-06-05T13:20:03","modified_gmt":"2025-06-05T05:44:03","slug":"https-badgameshow-com-steven-84","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-84\/","title":{"rendered":"Swift UIActivityIndicatorView \u4f7f\u7528\u6559\u5b78 &#8211; 2025 \u6700\u65b0\u7248\u8b80\u53d6\u52d5\u756b\u5be6\u4f5c"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, UIActivityIndicatorView, \u8b80\u53d6\u52d5\u756b\u6559\u5b78\"><\/p>\n<h1>Swift UIActivityIndicatorView \u4f7f\u7528\u6559\u5b78 &#8211; 2025 \u6700\u65b0\u7248\u8b80\u53d6\u52d5\u756b\u5be6\u4f5c<\/h1>\n<p>UIActivityIndicatorView \u662f iOS \u5167\u5efa\u7684\u8b80\u53d6\u52d5\u756b\u5143\u4ef6\uff0c\u53ef\u4ee5\u8b93\u4f7f\u7528\u8005\u6e05\u695a\u77e5\u9053\u7a0b\u5f0f\u6b63\u5728\u8655\u7406\u8cc7\u6599\uff0c\u800c\u4e0d\u662f\u986f\u5f97\u5361\u4f4f\u3002\u5728 Swift \u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u8f15\u9b06\u5730\u4f7f\u7528 UIActivityIndicatorView \u4f86\u5efa\u7acb\u8b80\u53d6\u52d5\u756b\u3002\u63a5\u4e0b\u4f86\uff0c\u6211\u5c07\u5e36\u4f60\u4e00\u6b65\u6b65\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528\u9019\u500b\u5143\u4ef6\uff0c\u4e26\u5206\u4eab\u6700\u4f73\u5be6\u8e10\u548c\u5ef6\u4f38\u61c9\u7528\u3002<\/p>\n<h2>\u5efa\u7acb UIActivityIndicatorView<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u5011\u8981\u5148\u5efa\u7acb UIActivityIndicatorView\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let activityIndicator = UIActivityIndicatorView(style: .medium)\n<\/code><\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e86 .medium \u98a8\u683c\uff0c\u4f60\u4e5f\u53ef\u4ee5\u9078\u64c7\u5176\u4ed6\u6a23\u5f0f\uff0c\u4f8b\u5982 .large \u6216 .medium\u3002\u9078\u64c7\u5408\u9069\u7684\u6a23\u5f0f\u53ef\u4ee5\u6839\u64da\u4f60\u7684 UI \u8a2d\u8a08\u9700\u6c42\u3002<\/p>\n<h2>\u8a2d\u5b9a UIActivityIndicatorView \u7684\u4f4d\u7f6e<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u70ba UIActivityIndicatorView \u8a2d\u5b9a\u4f4d\u7f6e\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">activityIndicator.center = view.center\n<\/code><\/pre>\n<p>\u9019\u6bb5\u7a0b\u5f0f\u78bc\u6703\u5c07 UIActivityIndicatorView \u7684\u4f4d\u7f6e\u8a2d\u5b9a\u5728\u8996\u5716\u7684\u4e2d\u5fc3\u3002\u82e5\u8981\u5c07\u5176\u653e\u7f6e\u5728\u5176\u4ed6\u4f4d\u7f6e\uff0c\u4f8b\u5982\u4e0a\u79fb 50 \u9ede\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">activityIndicator.center = CGPoint(x: view.center.x, y: view.center.y - 50)\n<\/code><\/pre>\n<h2>\u5c07 UIActivityIndicatorView \u52a0\u5165\u8996\u5716\u4e2d<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5c07 UIActivityIndicatorView \u52a0\u5165\u5230\u8996\u5716\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">view.addSubview(activityIndicator)\n<\/code><\/pre>\n<h2>\u958b\u59cb\u52d5\u756b<\/h2>\n<p>\u7576 UIActivityIndicatorView \u52a0\u5165\u8996\u5716\u5f8c\uff0c\u6211\u5011\u53ef\u4ee5\u958b\u59cb\u52d5\u756b\uff0c\u4f7f\u7528\u4ee5\u4e0b\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">activityIndicator.startAnimating()\n<\/code><\/pre>\n<p>\u9019\u6bb5\u7a0b\u5f0f\u78bc\u6703\u555f\u52d5 UIActivityIndicatorView \u7684\u52d5\u756b\uff0c\u8b93\u4f7f\u7528\u8005\u77e5\u9053\u7a0b\u5f0f\u6b63\u5728\u8655\u7406\u8cc7\u6599\u3002<\/p>\n<h2>\u505c\u6b62\u52d5\u756b<\/h2>\n<p>\u7576\u4efb\u52d9\u5b8c\u6210\u5f8c\uff0c\u6211\u5011\u9700\u8981\u505c\u6b62\u52d5\u756b\uff0c\u4f7f\u7528\u4ee5\u4e0b\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">activityIndicator.stopAnimating()\n<\/code><\/pre>\n<p>\u9019\u6bb5\u7a0b\u5f0f\u78bc\u6703\u505c\u6b62 UIActivityIndicatorView \u7684\u52d5\u756b\uff0c\u8b93\u4f7f\u7528\u8005\u77e5\u9053\u7a0b\u5f0f\u5df2\u7d93\u8655\u7406\u5b8c\u6240\u6709\u8cc7\u6599\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u4f7f\u7528 UIActivityIndicatorView \u6642\uff0c\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u554f\u984c\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u52d5\u756b\u4e0d\u986f\u793a\uff0c\u8acb\u78ba\u4fdd\u4f60\u5df2\u7d93\u5c07\u5176\u52a0\u5165\u5230\u8996\u5716\u4e2d\u4e26\u4e14\u547c\u53eb\u4e86 startAnimating()\u3002<\/li>\n<li>\u5982\u679c\u52d5\u756b\u986f\u793a\u4e0d\u6b63\u5e38\uff0c\u6aa2\u67e5\u6a23\u5f0f\u662f\u5426\u6b63\u78ba\u8a2d\u5b9a\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>UIActivityIndicatorView \u5e38\u7528\u65bc\u7db2\u7d61\u8acb\u6c42\u6216\u8cc7\u6599\u52a0\u8f09\u6642\uff0c\u4f60\u53ef\u4ee5\u5c07\u5176\u8207 URLSession \u7d50\u5408\u4f7f\u7528\uff0c\u8b93\u4f7f\u7528\u8005\u5728\u7b49\u5f85\u8cc7\u6599\u6642\u770b\u5230\u8b80\u53d6\u52d5\u756b\u3002<\/p>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">func fetchData() {\n    activityIndicator.startAnimating()\n    URLSession.shared.dataTask(with: url) { data, response, error in\n        DispatchQueue.main.async {\n            self.activityIndicator.stopAnimating()\n            \/\/ \u8655\u7406\u8cc7\u6599\n        }\n    }.resume()\n}\n<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-UIActivityIndicatorView\u4f7f\u7528\ud83d\udca4-\u8b80\u53d6\u52d5\u756b\u6559\u5b78_1675396321.897963.webp\" alt=\"Swift UIActivityIndicatorView\u4f7f\u7528\ud83d\udca4 - \u8b80\u53d6\u52d5\u756b\u6559\u5b78\" title=\"Swift UIActivityIndicatorView\u3001\u8b80\u53d6\u52d5\u756b\u3001iOS\u61c9\u7528\u7a0b\u5e8f\u3001\u8655\u7406\u4e2d\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>\u7d50\u8a9e<\/h2>\n<p>\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5b78\u7fd2\u4e86\u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528 UIActivityIndicatorView \u4f86\u5efa\u7acb\u8b80\u53d6\u52d5\u756b\u3002\u5e0c\u671b\u9019\u4e9b\u8cc7\u8a0a\u80fd\u5e6b\u52a9\u4f60\u66f4\u6d41\u66a2\u5730\u8655\u7406\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>Q1: UIActivityIndicatorView \u53ef\u4ee5\u81ea\u8a02\u6a23\u5f0f\u55ce\uff1f<\/h3>\n<p>A1: \u662f\u7684\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u6a23\u5f0f\u4f86\u81ea\u8a02 UIActivityIndicatorView\uff0c\u50cf\u662f .medium\u3001.large \u7b49\u3002<\/p>\n<h3>Q2: \u5982\u4f55\u986f\u793a\u52d5\u756b\u5728\u4e3b\u57f7\u884c\u7dd2\u4e2d\uff1f<\/h3>\n<p>A2: \u78ba\u4fdd\u5728\u4e3b\u57f7\u884c\u7dd2\u4e2d\u547c\u53eb startAnimating() \u548c stopAnimating()\uff0c\u53ef\u4ee5\u4f7f\u7528 DispatchQueue.main.async \u4f86\u78ba\u4fdd\u3002<\/p>\n<h3>Q3: \u4f55\u6642\u61c9\u8a72\u4f7f\u7528 UIActivityIndicatorView\uff1f<\/h3>\n<p>A3: \u7576\u4f60\u7684\u61c9\u7528\u7a0b\u5f0f\u9700\u8981\u9032\u884c\u8017\u6642\u64cd\u4f5c\u6216\u7db2\u7d61\u8acb\u6c42\u6642\uff0c\u4f7f\u7528 UIActivityIndicatorView \u662f\u4e00\u500b\u826f\u597d\u7684\u7528\u6236\u9ad4\u9a57\u8a2d\u8a08\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39Swift\u4e2dUIActivityIndicatorView\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u5728iOS\u61c9\u7528\u7a0b\u5e8f\u4e2d\u6dfb\u52a0\u8b80\u53d6\u52d5\u756b\uff0c\u8b93\u4f7f\u7528\u8005\u53ef\u4ee5\u66f4\u52a0\u76f4\u89c0\u7684\u77e5\u9053\u7a0b\u5e8f\u6b63\u5728\u8655\u7406\u4e2d\u3002<\/p>\n","protected":false},"author":1,"featured_media":6815,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[174,5],"tags":[173,9],"class_list":["post-6816","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-UIActivityIndicatorView\u4f7f\u7528\ud83d\udca4-\u8b80\u53d6\u52d5\u756b\u6559\u5b78_1675396321.897963.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1LW","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6816","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=6816"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6816\/revisions"}],"predecessor-version":[{"id":13553,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6816\/revisions\/13553"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/6815"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}