{"id":69,"date":"2025-06-02T10:27:18","date_gmt":"2025-06-05T03:12:17","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=69"},"modified":"2025-06-05T10:27:18","modified_gmt":"2025-06-05T03:12:17","slug":"swift-loading","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/swift-loading\/","title":{"rendered":"Swift \u52a0\u8f09\u52d5\u756b\u6559\u5b78\uff1a\u5982\u4f55\u4f7f\u7528 UIActivityIndicatorView \u5275\u5efa\u6d41\u66a2\u7684\u52a0\u8f09\u6548\u679c \ud83c\udf3c"},"content":{"rendered":"<p>&#8220;`html<\/p>\n<h1>Swift \u52a0\u8f09\u52d5\u756b\u6559\u5b78\uff1a\u5982\u4f55\u4f7f\u7528 UIActivityIndicatorView \u5275\u5efa\u6d41\u66a2\u7684\u52a0\u8f09\u6548\u679c \ud83c\udf3c<\/h1>\n<h2>\u7c21\u4ecb<\/h2>\n<p>\u5728\u958b\u767c\u61c9\u7528\u7a0b\u5f0f\u6642\uff0c\u7576\u9032\u884c\u7db2\u7d61\u8acb\u6c42\u6216\u6578\u64da\u52a0\u8f09\u6642\uff0c\u5982\u4f55\u6709\u6548\u5730\u544a\u77e5\u7528\u6236\u6b63\u5728\u9032\u884c\u52a0\u8f09\u64cd\u4f5c\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u9019\u6642\u5019\uff0c\u4f7f\u7528\u539f\u751f\u7684\u52a0\u8f09\u52d5\u756b UIActivityIndicatorView \u4f86\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u662f\u500b\u4e0d\u932f\u7684\u9078\u64c7\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528 UIActivityIndicatorView\uff0c\u4e26\u5206\u4eab\u6700\u4f73\u5be6\u8e10\u548c\u5be6\u4f5c\u7bc4\u4f8b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/imgur.com\/uzpyXKt.gif\" alt=\"Loading Animation Example\" title=\"\"><br \/>\n<img decoding=\"async\" src=\"https:\/\/imgur.com\/ZMwYV5k.gif\" alt=\"Loading Animation Example\" title=\"\"><br \/>\n<img decoding=\"async\" src=\"https:\/\/imgur.com\/DMASgzs.gif\" alt=\"Loading Animation Example\" title=\"\"><br \/>\n<img decoding=\"async\" src=\"https:\/\/imgur.com\/HVlWmWQ.gif\" alt=\"Loading Animation Example\" title=\"\"><br \/>\n<img decoding=\"async\" src=\"https:\/\/imgur.com\/RHHt75X.gif\" alt=\"Loading Animation Example\" title=\"\"><br \/>\n<img decoding=\"async\" src=\"https:\/\/imgur.com\/N3slfeL.gif\" alt=\"Loading Animation Example\" title=\"\"><\/p>\n<h2>\u6b65\u9a5f\u4e00\uff1a\u5ba3\u544a Loading \u52d5\u756b<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u61f6\u52a0\u8f09\u4e00\u500b UIActivityIndicatorView \u5be6\u4f8b\u3002\u9019\u88e1\u662f\u5982\u4f55\u9032\u884c\u5ba3\u544a\u7684\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nlazy var activityIndicator: UIActivityIndicatorView = {<br \/>\n    let activityIndicator = UIActivityIndicatorView(style: .large)<br \/>\n    activityIndicator.center = self.view.center<br \/>\n    return activityIndicator<br \/>\n}()<br \/>\n&#8220;`<\/p>\n<h2>\u6b65\u9a5f\u4e8c\uff1a\u5728\u8996\u5716\u52a0\u8f09\u6642\u6dfb\u52a0\u52d5\u756b<\/h2>\n<p>\u6211\u5011\u9700\u8981\u5728 viewDidLoad \u65b9\u6cd5\u4e2d\u5c07 activityIndicator \u6dfb\u52a0\u5230\u8996\u5716\u4e2d\uff1a<\/p>\n<p>&#8220;`swift<br \/>\noverride func viewDidLoad() {<br \/>\n    super.viewDidLoad()<br \/>\n    self.view.addSubview(activityIndicator)<br \/>\n}<br \/>\n&#8220;`<\/p>\n<h2>\u6b65\u9a5f\u4e09\uff1a\u958b\u59cb\u548c\u505c\u6b62 Loading \u52d5\u756b<\/h2>\n<p>\u7576\u9700\u8981\u986f\u793a\u52a0\u8f09\u52d5\u756b\u6642\uff0c\u8abf\u7528 startAnimating() \u65b9\u6cd5\uff0c\u7576\u52a0\u8f09\u5b8c\u6210\u6642\uff0c\u5247\u8abf\u7528 stopAnimating() \u65b9\u6cd5\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nactivityIndicator.startAnimating()<br \/>\n&#8220;`<\/p>\n<p>&#8220;`swift<br \/>\nactivityIndicator.stopAnimating()<br \/>\n&#8220;`<\/p>\n<h2>\u6b65\u9a5f\u56db\uff1a\u96b1\u85cf Loading \u52d5\u756b<\/h2>\n<p>\u70ba\u4e86\u8b93\u52d5\u756b\u5728\u505c\u6b62\u6642\u81ea\u52d5\u96b1\u85cf\uff0c\u6211\u5011\u53ef\u4ee5\u8a2d\u7f6e hidesWhenStopped \u5c6c\u6027\u70ba true\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nactivityIndicator.hidesWhenStopped = true<br \/>\n&#8220;`<\/p>\n<h2>\u6b65\u9a5f\u4e94\uff1a\u76e3\u807d Loading \u52d5\u756b\u72c0\u614b<\/h2>\n<p>\u5982\u679c\u9700\u8981\u6aa2\u67e5\u52d5\u756b\u662f\u5426\u6b63\u5728\u904b\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528 isAnimating \u5c6c\u6027\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nif activityIndicator.isAnimating {<br \/>\n    \/\/ \u52d5\u756b\u6b63\u5728\u904b\u884c<br \/>\n}<br \/>\n&#8220;`<\/p>\n<h2>\u6b65\u9a5f\u516d\uff1a\u81ea\u5b9a\u7fa9 Loading \u52d5\u756b\u984f\u8272<\/h2>\n<p>\u4f60\u53ef\u4ee5\u6839\u64da\u9700\u8981\u8a2d\u7f6e activityIndicator \u7684\u984f\u8272\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nactivityIndicator.color = .red<br \/>\n&#8220;`<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/imgur.com\/uzpyXKt.gif\" alt=\"Red Loading Animation\" title=\"\"><\/p>\n<h2>\u6b65\u9a5f\u4e03\uff1a\u9078\u64c7 Loading \u52d5\u756b\u6a23\u5f0f<\/h2>\n<p>UIActivityIndicatorView \u63d0\u4f9b\u4e86\u591a\u7a2e\u6a23\u5f0f\u4f9b\u9078\u64c7\uff0c\u4f60\u53ef\u4ee5\u6839\u64da\u9700\u8981\u9078\u64c7\u5408\u9069\u7684\u6a23\u5f0f\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nactivityIndicator.style = .gray<br \/>\n&#8220;`<br \/>\n<img decoding=\"async\" src=\"https:\/\/imgur.com\/ZMwYV5k.gif\" alt=\"Gray Loading Animation\" title=\"\"><\/p>\n<p>&#8220;`swift<br \/>\nactivityIndicator.style = .large<br \/>\n&#8220;`<br \/>\n<img decoding=\"async\" src=\"https:\/\/imgur.com\/DMASgzs.gif\" alt=\"Large Loading Animation\" title=\"\"><\/p>\n<p>&#8220;`swift<br \/>\nactivityIndicator.style = .medium<br \/>\n&#8220;`<br \/>\n<img decoding=\"async\" src=\"https:\/\/imgur.com\/HVlWmWQ.gif\" alt=\"Medium Loading Animation\" title=\"\"><\/p>\n<p>&#8220;`swift<br \/>\nactivityIndicator.style = .white<br \/>\n&#8220;`<br \/>\n<img decoding=\"async\" src=\"https:\/\/imgur.com\/RHHt75X.gif\" alt=\"White Loading Animation\" title=\"\"><\/p>\n<p>&#8220;`swift<br \/>\nactivityIndicator.style = .whiteLarge<br \/>\n&#8220;`<br \/>\n<img decoding=\"async\" src=\"https:\/\/imgur.com\/N3slfeL.gif\" alt=\"White Large Loading Animation\" title=\"\"><\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u4f7f\u7528 UIActivityIndicatorView \u53ef\u4ee5\u7c21\u55ae\u5730\u589e\u52a0\u61c9\u7528\u7a0b\u5e8f\u7684\u53ef\u7528\u6027\u548c\u7f8e\u89c0\u6027\u3002\u6b63\u78ba\u5730\u8655\u7406\u52a0\u8f09\u52d5\u756b\u53ef\u4ee5\u63d0\u9ad8\u7528\u6236\u9ad4\u9a57\uff0c\u8b93\u7528\u6236\u5728\u7b49\u5f85\u7684\u904e\u7a0b\u4e2d\u4e0d\u6703\u611f\u5230\u7121\u804a\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>Q1: UIActivityIndicatorView \u53ef\u4ee5\u81ea\u5b9a\u7fa9\u54ea\u4e9b\u5c6c\u6027\uff1f<\/h3>\n<p>A: UIActivityIndicatorView \u53ef\u4ee5\u81ea\u5b9a\u7fa9\u984f\u8272\u3001\u6a23\u5f0f\uff08\u5982 .medium\u3001.large \u7b49\uff09\u548c\u4f4d\u7f6e\u7b49\u5c6c\u6027\u3002<\/p>\n<h3>Q2: \u5982\u4f55\u5728\u7db2\u7d61\u8acb\u6c42\u671f\u9593\u4f7f\u7528\u52a0\u8f09\u52d5\u756b\uff1f<\/h3>\n<p>A: \u5728\u767c\u8d77\u7db2\u7d61\u8acb\u6c42\u4e4b\u524d\u8abf\u7528 startAnimating()\uff0c\u8acb\u6c42\u5b8c\u6210\u5f8c\u8abf\u7528 stopAnimating()\u3002<\/p>\n<h3>Q3: \u5982\u4f55\u5728\u4e0d\u540c\u7684\u8996\u5716\u63a7\u5236\u5668\u4e2d\u91cd\u8907\u4f7f\u7528\u52a0\u8f09\u52d5\u756b\uff1f<\/h3>\n<p>A: \u4f60\u53ef\u4ee5\u5c07 UIActivityIndicatorView \u7684\u521d\u59cb\u5316\u548c\u914d\u7f6e\u653e\u5165\u4e00\u500b\u55ae\u7368\u7684\u51fd\u6578\uff0c\u7136\u5f8c\u5728\u9700\u8981\u7684\u8996\u5716\u63a7\u5236\u5668\u4e2d\u8abf\u7528\u9019\u500b\u51fd\u6578\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8220;`<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`html Swift \u52a0\u8f09\u52d5\u756b\u6559\u5b78&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-17","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/69","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=69"}],"version-history":[{"count":7,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":7555,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/69\/revisions\/7555"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}