{"id":6241,"date":"2024-07-08T17:16:12","date_gmt":"2024-07-08T09:16:12","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6241"},"modified":"2024-07-08T17:17:06","modified_gmt":"2024-07-08T09:17:06","slug":"ios-%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0%e4%b8%80%e4%b8%aa%e5%9b%be%e6%a0%87%e6%97%8b%e8%bd%ac%e3%80%81%e8%b7%b3%e5%8a%a8%e7%9a%84%e5%8a%a8%e7%94%bb","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6241","title":{"rendered":"iOS \u600e\u4e48\u5b9e\u73b0\u4e00\u4e2a\u56fe\u6807\u65cb\u8f6c\u3001\u8df3\u52a8\u7684\u52a8\u753b"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u975e\u539f\u521b\u3001ChatGPT \u95ee\u7b54\u751f\u6210\uff0c\u80cc\u666f\u662f\u770b\u5230 CWMoney App \u7684\u52a8\u753b\u8bf1\u4eba\uff0c\u8be5App\u5185\u7f6e\u4e86POP\u5f00\u6e90\u5e93\uff0c\u4e86\u89e3\u4e00\u4e0b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 iOS \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 Core Animation \u6846\u67b6\uff08\u5982 <code>CAAnimation<\/code>\uff09\u6765\u5b9e\u73b0\u56fe\u6807\u7684\u65cb\u8f6c\u548c\u8df3\u52a8\u52a8\u753b\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528 Swift \u548c Core Animation \u5b9e\u73b0\u56fe\u6807\u65cb\u8f6c\u548c\u8df3\u52a8\u7684\u793a\u4f8b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u65cb\u8f6c\u52a8\u753b<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u6211\u4eec\u6765\u770b\u5982\u4f55\u5b9e\u73b0\u56fe\u6807\u7684\u65cb\u8f6c\u52a8\u753b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import UIKit\n\nclass ViewController: UIViewController {\n    @IBOutlet weak var imageView: UIImageView!\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        rotateAnimation()\n    }\n\n    func rotateAnimation() {\n        let rotation = CABasicAnimation(keyPath: \"transform.rotation\")\n        rotation.toValue = NSNumber(value: Double.pi * 2)\n        rotation.duration = 1.0\n        rotation.isCumulative = true\n        rotation.repeatCount = Float.infinity\n        imageView.layer.add(rotation, forKey: \"rotationAnimation\")\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u8df3\u52a8\u52a8\u753b<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u4e0b\u6765\u662f\u8df3\u52a8\u52a8\u753b\u7684\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import UIKit\n\nclass ViewController: UIViewController {\n    @IBOutlet weak var imageView: UIImageView!\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        jumpAnimation()\n    }\n\n    func jumpAnimation() {\n        let jump = CAKeyframeAnimation(keyPath: \"transform.translation.y\")\n        jump.values = &#91;0, -10, 0]\n        jump.keyTimes = &#91;0, 0.5, 1]\n        jump.duration = 0.5\n        jump.repeatCount = Float.infinity\n        imageView.layer.add(jump, forKey: \"jumpAnimation\")\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u65cb\u8f6c\u548c\u8df3\u52a8\u52a8\u753b\u7ed3\u5408<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\uff0c\u6211\u4eec\u5c06\u65cb\u8f6c\u548c\u8df3\u52a8\u52a8\u753b\u7ed3\u5408\u8d77\u6765\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import UIKit\n\nclass ViewController: UIViewController {\n    @IBOutlet weak var imageView: UIImageView!\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        rotateAndJumpAnimation()\n    }\n\n    func rotateAndJumpAnimation() {\n        \/\/ \u65cb\u8f6c\u52a8\u753b\n        let rotation = CABasicAnimation(keyPath: \"transform.rotation\")\n        rotation.toValue = NSNumber(value: Double.pi * 2)\n        rotation.duration = 1.0\n        rotation.isCumulative = true\n        rotation.repeatCount = Float.infinity\n\n        \/\/ \u8df3\u52a8\u52a8\u753b\n        let jump = CAKeyframeAnimation(keyPath: \"transform.translation.y\")\n        jump.values = &#91;0, -10, 0]\n        jump.keyTimes = &#91;0, 0.5, 1]\n        jump.duration = 0.5\n        jump.repeatCount = Float.infinity\n\n        \/\/ \u5c06\u4e24\u4e2a\u52a8\u753b\u7ec4\u5408\u8d77\u6765\n        let group = CAAnimationGroup()\n        group.animations = &#91;rotation, jump]\n        group.duration = 1.0\n        group.repeatCount = Float.infinity\n\n        imageView.layer.add(group, forKey: \"rotateAndJumpAnimation\")\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u89e3\u91ca<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u65cb\u8f6c\u52a8\u753b<\/strong>\uff1a\u4f7f\u7528 <code>CABasicAnimation<\/code> \u6765\u5b9e\u73b0\uff0c\u52a8\u753b\u7684\u5173\u952e\u8def\u5f84\u4e3a <code>transform.rotation<\/code>\uff0c\u8868\u793a\u56f4\u7ed5 Z \u8f74\u7684\u65cb\u8f6c\u3002<code>toValue<\/code> \u8bbe\u7f6e\u4e3a <code>Double.pi * 2<\/code>\uff0c\u8868\u793a\u65cb\u8f6c\u4e00\u5468\uff0c<code>duration<\/code> \u8868\u793a\u52a8\u753b\u6301\u7eed\u65f6\u95f4\uff0c<code>repeatCount<\/code> \u8868\u793a\u52a8\u753b\u91cd\u590d\u6b21\u6570\u3002<\/li>\n\n\n\n<li><strong>\u8df3\u52a8\u52a8\u753b<\/strong>\uff1a\u4f7f\u7528 <code>CAKeyframeAnimation<\/code> \u6765\u5b9e\u73b0\uff0c\u52a8\u753b\u7684\u5173\u952e\u8def\u5f84\u4e3a <code>transform.translation.y<\/code>\uff0c\u8868\u793a\u6cbf Y \u8f74\u7684\u5e73\u79fb\u3002<code>values<\/code> \u8bbe\u7f6e\u4e3a <code>[0, -10, 0]<\/code>\uff0c\u8868\u793a\u8df3\u52a8\u7684\u9ad8\u5ea6\uff0c<code>keyTimes<\/code> \u8bbe\u7f6e\u4e3a <code>[0, 0.5, 1]<\/code>\uff0c\u8868\u793a\u52a8\u753b\u5728\u65f6\u95f4\u4e0a\u7684\u5206\u914d\uff0c<code>duration<\/code> \u8868\u793a\u52a8\u753b\u6301\u7eed\u65f6\u95f4\uff0c<code>repeatCount<\/code> \u8868\u793a\u52a8\u753b\u91cd\u590d\u6b21\u6570\u3002<\/li>\n\n\n\n<li><strong>\u7ec4\u5408\u52a8\u753b<\/strong>\uff1a\u4f7f\u7528 <code>CAAnimationGroup<\/code> \u5c06\u65cb\u8f6c\u548c\u8df3\u52a8\u52a8\u753b\u7ec4\u5408\u8d77\u6765\uff0c\u4f7f\u5176\u540c\u65f6\u6267\u884c\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728 iOS \u5e94\u7528\u4e2d\u5b9e\u73b0\u4e00\u4e2a\u56fe\u6807\u65cb\u8f6c\u548c\u8df3\u52a8\u7684\u52a8\u753b\u6548\u679c\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u95ee\uff1a\u4f7f\u7528 POP \u5f00\u6e90\u5e93\u53ef\u4ee5\u5b9e\u73b0\u7c7b\u4f3c\u6548\u679c\u5417\uff1f\u5982\u4f55\u5b9e\u73b0\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u4f7f\u7528 Facebook \u7684 <code>POP<\/code> \u52a8\u753b\u5e93\u6765\u5b9e\u73b0\u7c7b\u4f3c\u7684\u65cb\u8f6c\u548c\u8df3\u52a8\u52a8\u753b\u6548\u679c\u3002<code>POP<\/code> \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u52a8\u753b\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u52a8\u753b\u7c7b\u578b\u548c\u7b80\u5355\u7684\u63a5\u53e3\u3002\u4e0b\u9762\u662f\u5982\u4f55\u4f7f\u7528 <code>POP<\/code> \u6765\u5b9e\u73b0\u56fe\u6807\u7684\u65cb\u8f6c\u548c\u8df3\u52a8\u52a8\u753b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b89\u88c5 POP<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u901a\u8fc7 CocoaPods \u5b89\u88c5 <code>POP<\/code>\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5728 <code>Podfile<\/code> \u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   pod 'pop'<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li>\u8fd0\u884c <code>pod install<\/code>\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u65cb\u8f6c\u52a8\u753b<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528 <code>POP<\/code> \u5b9e\u73b0\u56fe\u6807\u7684\u65cb\u8f6c\u52a8\u753b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import UIKit\nimport pop\n\nclass ViewController: UIViewController {\n    @IBOutlet weak var imageView: UIImageView!\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        rotateAnimation()\n    }\n\n    func rotateAnimation() {\n        let rotationAnimation = POPBasicAnimation(propertyNamed: kPOPLayerRotation)\n        rotationAnimation?.toValue = NSNumber(value: Double.pi * 2)\n        rotationAnimation?.duration = 1.0\n        rotationAnimation?.repeatForever = true\n        imageView.layer.pop_add(rotationAnimation, forKey: \"rotationAnimation\")\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u8df3\u52a8\u52a8\u753b<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528 <code>POP<\/code> \u5b9e\u73b0\u56fe\u6807\u7684\u8df3\u52a8\u52a8\u753b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import UIKit\nimport pop\n\nclass ViewController: UIViewController {\n    @IBOutlet weak var imageView: UIImageView!\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        jumpAnimation()\n    }\n\n    func jumpAnimation() {\n        let jumpAnimation = POPSpringAnimation(propertyNamed: kPOPLayerPositionY)\n        jumpAnimation?.fromValue = imageView.layer.position.y\n        jumpAnimation?.toValue = imageView.layer.position.y - 10\n        jumpAnimation?.springBounciness = 20\n        jumpAnimation?.repeatForever = true\n        imageView.layer.pop_add(jumpAnimation, forKey: \"jumpAnimation\")\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u65cb\u8f6c\u548c\u8df3\u52a8\u52a8\u753b\u7ed3\u5408<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c06\u65cb\u8f6c\u548c\u8df3\u52a8\u52a8\u753b\u7ed3\u5408\u8d77\u6765\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import UIKit\nimport pop\n\nclass ViewController: UIViewController {\n    @IBOutlet weak var imageView: UIImageView!\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        rotateAndJumpAnimation()\n    }\n\n    func rotateAndJumpAnimation() {\n        \/\/ \u65cb\u8f6c\u52a8\u753b\n        let rotationAnimation = POPBasicAnimation(propertyNamed: kPOPLayerRotation)\n        rotationAnimation?.toValue = NSNumber(value: Double.pi * 2)\n        rotationAnimation?.duration = 1.0\n        rotationAnimation?.repeatForever = true\n        imageView.layer.pop_add(rotationAnimation, forKey: \"rotationAnimation\")\n\n        \/\/ \u8df3\u52a8\u52a8\u753b\n        let jumpAnimation = POPSpringAnimation(propertyNamed: kPOPLayerPositionY)\n        jumpAnimation?.fromValue = imageView.layer.position.y\n        jumpAnimation?.toValue = imageView.layer.position.y - 10\n        jumpAnimation?.springBounciness = 20\n        jumpAnimation?.repeatForever = true\n        imageView.layer.pop_add(jumpAnimation, forKey: \"jumpAnimation\")\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u89e3\u91ca<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u65cb\u8f6c\u52a8\u753b<\/strong>\uff1a\u4f7f\u7528 <code>POPBasicAnimation<\/code> \u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u52a8\u753b\uff0c\u5c5e\u6027\u4e3a <code>kPOPLayerRotation<\/code>\uff0c\u8868\u793a\u56f4\u7ed5 Z \u8f74\u7684\u65cb\u8f6c\u3002<code>toValue<\/code> \u8bbe\u7f6e\u4e3a <code>Double.pi * 2<\/code> \u8868\u793a\u65cb\u8f6c\u4e00\u5468\uff0c<code>duration<\/code> \u8868\u793a\u52a8\u753b\u6301\u7eed\u65f6\u95f4\uff0c<code>repeatForever<\/code> \u8bbe\u7f6e\u4e3a <code>true<\/code> \u8868\u793a\u52a8\u753b\u65e0\u9650\u5faa\u73af\u3002<\/li>\n\n\n\n<li><strong>\u8df3\u52a8\u52a8\u753b<\/strong>\uff1a\u4f7f\u7528 <code>POPSpringAnimation<\/code> \u521b\u5efa\u4e00\u4e2a\u5f39\u7c27\u52a8\u753b\uff0c\u5c5e\u6027\u4e3a <code>kPOPLayerPositionY<\/code>\uff0c\u8868\u793a\u6cbf Y \u8f74\u7684\u5e73\u79fb\u3002<code>fromValue<\/code> \u8bbe\u7f6e\u4e3a\u56fe\u6807\u7684\u521d\u59cb Y \u8f74\u4f4d\u7f6e\uff0c<code>toValue<\/code> \u8bbe\u7f6e\u4e3a\u521d\u59cb\u4f4d\u7f6e\u51cf\u53bb 10\uff0c\u8868\u793a\u8df3\u52a8\u7684\u9ad8\u5ea6\uff0c<code>springBounciness<\/code> \u8bbe\u7f6e\u4e3a 20\uff0c\u8868\u793a\u5f39\u7c27\u7684\u5f39\u6027\uff0c<code>repeatForever<\/code> \u8bbe\u7f6e\u4e3a <code>true<\/code> \u8868\u793a\u52a8\u753b\u65e0\u9650\u5faa\u73af\u3002<\/li>\n\n\n\n<li><strong>\u7ec4\u5408\u52a8\u753b<\/strong>\uff1a\u76f4\u63a5\u5c06\u4e24\u4e2a\u52a8\u753b\u6dfb\u52a0\u5230\u56fe\u6807\u7684\u56fe\u5c42\u4e0a\uff0c\u4f7f\u5176\u540c\u65f6\u6267\u884c\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>POP<\/code> \u52a8\u753b\u5e93\u5728 iOS \u5e94\u7528\u4e2d\u5b9e\u73b0\u56fe\u6807\u7684\u65cb\u8f6c\u548c\u8df3\u52a8\u52a8\u753b\u3002<code>POP<\/code> \u52a8\u753b\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u52a8\u753b\u7c7b\u578b\u548c\u7075\u6d3b\u7684\u914d\u7f6e\u9009\u9879\uff0c\u4f7f\u5f97\u52a8\u753b\u6548\u679c\u66f4\u5bb9\u6613\u5b9e\u73b0\u548c\u63a7\u5236\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u975e\u539f\u521b\u3001ChatGPT \u95ee\u7b54\u751f\u6210\uff0c\u80cc\u666f\u662f\u770b\u5230 CWMoney App \u7684\u52a8\u753b\u8bf1\u4eba\uff0c\u8be5App\u5185\u7f6e\u4e86POP\u5f00\u6e90\u5e93\uff0c&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6241\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-6241","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6241"}],"version-history":[{"count":2,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6241\/revisions"}],"predecessor-version":[{"id":6243,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6241\/revisions\/6243"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}