{"id":346976,"date":"2023-03-19T15:01:29","date_gmt":"2023-03-19T15:01:29","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=346976"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=346976","title":{"rendered":"<span>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0439, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0445 \u043e\u0442 \u043f\u0440\u043e\u043a\u0440\u0443\u0442\u043a\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e UIScrollView<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u043e \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0435 \u043e\u0442 \u0441\u043a\u0440\u043e\u043b\u043b\u0430. \u0412 <a href=\"https:\/\/habr.com\/ru\/post\/721894\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043b, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u0435 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438, \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u0441\u043b\u0430\u0439\u0434\u0435\u0440 \u0441 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438. \u0421 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e &#8212; \u043d\u0430\u0448\u0430 \u0444\u0430\u043d\u0442\u0430\u0437\u0438\u044f \u0431\u0435\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u0430, \u043d\u043e \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0443\u0441\u044c \u0442\u0440\u0435\u043c\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0438\u0442\u044c \u0432\u0430\u0441 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a\u043e\u0434\u0430:<\/p>\n<ul>\n<li>\n<p>\u0424\u0435\u0439\u0434<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430<\/p>\n<\/li>\n<\/ul>\n<p><strong>TLDR<\/strong>:\u00a0<a href=\"https:\/\/github.com\/BugChef\/ScrollDependentAnimation-part2\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438<\/a><\/p>\n<h2>Flashback<\/h2>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aae\/b3f\/c92\/aaeb3fc92e98b32d72fce9f02880ea68.gif\" width=\"400\" height=\"300\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aae\/b3f\/c92\/aaeb3fc92e98b32d72fce9f02880ea68.gif\"\/><\/figure>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u043d\u0435 \u0447\u0438\u0442\u0430\u043b\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u0438 \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u0438 \u0431\u044b \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0435\u0451 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u0435. \u041e\u0434\u043d\u0430\u043a\u043e, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0447\u0442\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u0430\u0431\u0437\u0430\u0446, \u0442\u0430\u043a \u043a\u0430\u043a \u0437\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u043a\u0440\u0430\u0442\u043a\u043e\u0435 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b, \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438. \u042d\u0442\u043e \u0441\u0430\u043c\u0430\u044f \u0432\u0430\u0436\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c, \u0438 \u043c\u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0435\u0451 \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c. \u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0434\u043b\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435\u00a0<strong>UIScrollView<\/strong>\u00a0&#8212;\u00a0<strong>scrollViewDidScroll<\/strong>:<\/p>\n<pre><code class=\"swift\">func scrollViewDidScroll(_ scrollView: UIScrollView) { let currentContentOffsetY = scrollView.contentOffset.y     let scrollDiff = currentContentOffsetY - previousContentOffsetY      \/\/ \u0412\u0435\u0440\u0445\u043d\u044f\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430 \u043d\u0430\u0447\u0430\u043b\u0430 bounce \u044d\u0444\u0444\u0435\u043a\u0442\u0430     let bounceBorderContentOffsetY = -scrollView.contentInset.top      let contentMovesUp = scrollDiff > 0 &amp;&amp; currentContentOffsetY > bounceBorderContentOffsetY     let contentMovesDown = scrollDiff &lt; 0 &amp;&amp; currentContentOffsetY &lt; bounceBorderContentOffsetY      let currentConstraintConstant = animatedConstraint!.constant     var newConstraintConstant = currentConstraintConstant      if contentMovesUp { \/\/ \u0423\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 \u043a\u043e\u043d\u0441\u0442\u0440\u044d\u0439\u043d\u0442\u0430         newConstraintConstant = max(currentConstraintConstant - scrollDiff, minConstraintConstant)     } else if contentMovesDown {         \/\/ \u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 \u043a\u043e\u043d\u0441\u0442\u0440\u044d\u0439\u043d\u0442\u0430         newConstraintConstant = min(currentConstraintConstant - scrollDiff, maxConstraintConstant)     }      \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u0432\u044b\u0441\u043e\u0442\u0443 \u0438 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c \u0441\u043a\u0440\u043e\u043b\u043b, \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b     if newConstraintConstant != currentConstraintConstant { animatedConstraint?.constant = newConstraintConstant         scrollView.contentOffset.y = previousContentOffsetY     }      \/\/ \u041f\u0440\u043e\u0446\u0435\u043d\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438     let animationCompletionPercent = (maxConstraintConstant - currentConstraintConstant) \/ (maxConstraintConstant - minConstraintConstant)     progressView.progress = Float(animationCompletionPercent)      previousContentOffsetY = scrollView.contentOffset.y }<\/code><\/pre>\n<p>\u0420\u0430\u0441\u0447\u0451\u0442 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435, \u043e\u043d \u0442\u043e \u043d\u0430\u043c \u0438 \u043d\u0443\u0436\u0435\u043d:<\/p>\n<pre><code class=\"swift\">\/\/ \u041f\u0440\u043e\u0446\u0435\u043d\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 let animationCompletionPercent = (maxConstraintConstant - currentConstraintConstant) \/ (maxConstraintConstant - minConstraintConstant)<\/code><\/pre>\n<h2>\u0424\u0435\u0439\u0434 UIView<\/h2>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d04\/d61\/41c\/d04d6141cb5f502848c6102fb9568a4d.gif\" width=\"223\" height=\"482\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d04\/d61\/41c\/d04d6141cb5f502848c6102fb9568a4d.gif\"\/><\/figure>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e: \u0430\u043b\u044c\u0444\u0430\u00a0<strong>UIView <\/strong>&#8212; \u044d\u0442\u043e<strong> <\/strong>\u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"swift\">\/\/ \u041f\u0440\u043e\u0446\u0435\u043d\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 let animationCompletionPercent = (maxConstraintConstant - currentConstraintConstant) \/ (maxConstraintConstant - minConstraintConstant) fadeView.alpha = animationCompletionPercent<\/code><\/pre>\n<h2>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 UIView<\/h2>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0f3\/534\/6b7\/0f35346b7ee689ba18de6209c5c0d3d9.gif\" width=\"223\" height=\"482\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0f3\/534\/6b7\/0f35346b7ee689ba18de6209c5c0d3d9.gif\"\/><\/figure>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u0444\u0444\u0438\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438. \u0414\u0432\u0443\u0445\u043c\u0435\u0440\u043d\u044b\u0435 \u0430\u0444\u0444\u0438\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043d\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 3&#215;3, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0439, \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0430\u043d\u0443\u0442 \u043d\u043e\u0432\u044b\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0438. \u0415\u0441\u043b\u0438 \u0432\u043a\u0440\u0430\u0442\u0446\u0435, \u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u0444\u0444\u0438\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439\u00a0<strong>UIView<\/strong>\u00a0\u043c\u043e\u0436\u043d\u043e \u0434\u0432\u0438\u0433\u0430\u0442\u044c, \u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c\u00a0<strong>UIViewPropertyAnimator<\/strong>\u00a0\u0434\u043b\u044f \u0430\u043d\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\u00a0<strong>UIView<\/strong>.<\/p>\n<pre><code class=\"swift\">class CoordinatesChangeView: UIView {     var animationCompletionPercentage: Double = 0 {         didSet { animator.fractionComplete = animationCompletionPercentage }     }  private let side: CGFloat = 60  private lazy var animator = UIViewPropertyAnimator(duration: 0.1, curve: .easeIn) { [weak self] in         guard let self else { return }          self.imageView.transform = CGAffineTransform(translationX: self.side - self.bounds.width, y: 0)     } }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438\u00a0<strong>CoordinatesChangeView<\/strong>. \u0412 \u0441\u0430\u043c\u043e\u043c\u00a0<strong>UIViewController<\/strong>\u00a0\u0432\u0441\u0451 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435:<\/p>\n<pre><code class=\"swift\">\/\/ \u041f\u0440\u043e\u0446\u0435\u043d\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 let animationCompletionPercent = (maxConstraintConstant - currentConstraintConstant) \/ (maxConstraintConstant - minConstraintConstant) coordinateChangeView.animationCompletionPercentage = animationCompletionPercent<\/code><\/pre>\n<h2>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 UIView<\/h2>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a1c\/cc2\/2cf\/a1ccc22cfc1fdf82057a3ddbac2b2d1d.gif\" width=\"223\" height=\"482\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a1c\/cc2\/2cf\/a1ccc22cfc1fdf82057a3ddbac2b2d1d.gif\"\/><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0444\u0444\u0438\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0430\u043d\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437\u00a0<strong>UIViewPropertyAnimator<\/strong>, \u043d\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u043c, \u0430 \u0441\u0430\u043c\u0438\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0435\u0439\u043d\u0442\u043e\u043c:<\/p>\n<pre><code class=\"swift\">private let minConstraintConstant: CGFloat = 50 private let maxConstraintConstant: CGFloat = 200  private var animatedConstraint: NSLayoutConstraint? private var avatarHeightConstraint: NSLayoutConstraint?  private func setupAvatarView() { view.addSubview(avatarImageView)              avatarHeightConstraint = avatarImageView.heightAnchor.constraint(equalToConstant: maxConstraintConstant)              NSLayoutConstraint.activate([ avatarHeightConstraint!,         avatarImageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),         avatarImageView.heightAnchor.constraint(equalTo: avatarImageView.widthAnchor, multiplier: 1.0),         avatarImageView.centerXAnchor.constraint(equalTo: view.centerXAnchor), ]) }<\/code><\/pre>\n<p>\u0412 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435 \u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 \u0438 \u0431\u0443\u0434\u0443 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0451 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435\u00a0<strong>scrollViewDidScroll:<\/strong><\/p>\n<pre><code>\/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u0432\u044b\u0441\u043e\u0442\u0443 \u0438 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c \u0441\u043a\u0440\u043e\u043b\u043b, \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b if newConstraintConstant != currentConstraintConstant { animatedConstraint?.constant = newConstraintConstant     scrollView.contentOffset.y = previousContentOffsetY }          \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u0432\u044b\u0441\u043e\u0442\u0443 \u0430\u0432\u0430\u0442\u0430\u0440\u0430, \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b if newConstraintConstant != avatarHeightConstraint!.constant { avatarHeightConstraint?.constant = currentConstraintConstant }<\/code><\/pre>\n<p>\u0418\u0437\u043c\u0435\u043d\u044f\u044e \u0432\u044b\u0441\u043e\u0442\u0443 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0441 \u043a\u043e\u0441\u043d\u0442\u0440\u0435\u0439\u043d\u0442\u043e\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b &#8212; \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041c\u043d\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u043d\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u044f \u043c\u0435\u043d\u044f\u044e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u043d\u043e, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439. \u042f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0443 \u0432\u0430\u0441 \u0431\u044b\u043b\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0438\u0449\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u0439. \u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0437\u0434\u0435\u0441\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a\u043e\u0434\u0430. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443\u0442\u044c, \u0447\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043b\u0430\u0434\u0435\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u043d\u043e \u0438 \u0443\u043c\u0435\u0442\u044c \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/723386\/\"> https:\/\/habr.com\/ru\/post\/723386\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042d\u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u043e \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0438\u0435 \u043e\u0442 \u0441\u043a\u0440\u043e\u043b\u043b\u0430. \u0412 <a href=\"https:\/\/habr.com\/ru\/post\/721894\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u044f \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043b, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u0435 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438, \u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b \u0441\u043b\u0430\u0439\u0434\u0435\u0440 \u0441 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438. \u0421 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0442\u043e \u0443\u0433\u043e\u0434\u043d\u043e &#8212; \u043d\u0430\u0448\u0430 \u0444\u0430\u043d\u0442\u0430\u0437\u0438\u044f \u0431\u0435\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u0430, \u043d\u043e \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0443\u0441\u044c \u0442\u0440\u0435\u043c\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0438\u0442\u044c \u0432\u0430\u0441 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a\u043e\u0434\u0430:<\/p>\n<ul>\n<li>\n<p>\u0424\u0435\u0439\u0434<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430<\/p>\n<\/li>\n<\/ul>\n<p><strong>TLDR<\/strong>:\u00a0<a href=\"https:\/\/github.com\/BugChef\/ScrollDependentAnimation-part2\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438<\/a><\/p>\n<h2>Flashback<\/h2>\n<figure class=\"\"><\/figure>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u044b \u043d\u0435 \u0447\u0438\u0442\u0430\u043b\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u0438 \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u0438 \u0431\u044b \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0435\u0451 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u0435. \u041e\u0434\u043d\u0430\u043a\u043e, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0447\u0442\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u0430\u0431\u0437\u0430\u0446, \u0442\u0430\u043a \u043a\u0430\u043a \u0437\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u043a\u0440\u0430\u0442\u043a\u043e\u0435 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b, \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u043a\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438. \u042d\u0442\u043e \u0441\u0430\u043c\u0430\u044f \u0432\u0430\u0436\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c, \u0438 \u043c\u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0435\u0451 \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c. \u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0434\u043b\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043d\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435\u00a0<strong>UIScrollView<\/strong>\u00a0&#8212;\u00a0<strong>scrollViewDidScroll<\/strong>:<\/p>\n<pre><code class=\"swift\">func scrollViewDidScroll(_ scrollView: UIScrollView) { let currentContentOffsetY = scrollView.contentOffset.y     let scrollDiff = currentContentOffsetY - previousContentOffsetY      \/\/ \u0412\u0435\u0440\u0445\u043d\u044f\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430 \u043d\u0430\u0447\u0430\u043b\u0430 bounce \u044d\u0444\u0444\u0435\u043a\u0442\u0430     let bounceBorderContentOffsetY = -scrollView.contentInset.top      let contentMovesUp = scrollDiff > 0 &amp;&amp; currentContentOffsetY > bounceBorderContentOffsetY     let contentMovesDown = scrollDiff &lt; 0 &amp;&amp; currentContentOffsetY &lt; bounceBorderContentOffsetY      let currentConstraintConstant = animatedConstraint!.constant     var newConstraintConstant = currentConstraintConstant      if contentMovesUp { \/\/ \u0423\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 \u043a\u043e\u043d\u0441\u0442\u0440\u044d\u0439\u043d\u0442\u0430         newConstraintConstant = max(currentConstraintConstant - scrollDiff, minConstraintConstant)     } else if contentMovesDown {         \/\/ \u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 \u043a\u043e\u043d\u0441\u0442\u0440\u044d\u0439\u043d\u0442\u0430         newConstraintConstant = min(currentConstraintConstant - scrollDiff, maxConstraintConstant)     }      \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u0432\u044b\u0441\u043e\u0442\u0443 \u0438 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c \u0441\u043a\u0440\u043e\u043b\u043b, \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b     if newConstraintConstant != currentConstraintConstant { animatedConstraint?.constant = newConstraintConstant         scrollView.contentOffset.y = previousContentOffsetY     }      \/\/ \u041f\u0440\u043e\u0446\u0435\u043d\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438     let animationCompletionPercent = (maxConstraintConstant - currentConstraintConstant) \/ (maxConstraintConstant - minConstraintConstant)     progressView.progress = Float(animationCompletionPercent)      previousContentOffsetY = scrollView.contentOffset.y }<\/code><\/pre>\n<p>\u0420\u0430\u0441\u0447\u0451\u0442 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435, \u043e\u043d \u0442\u043e \u043d\u0430\u043c \u0438 \u043d\u0443\u0436\u0435\u043d:<\/p>\n<pre><code class=\"swift\">\/\/ \u041f\u0440\u043e\u0446\u0435\u043d\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 let animationCompletionPercent = (maxConstraintConstant - currentConstraintConstant) \/ (maxConstraintConstant - minConstraintConstant)<\/code><\/pre>\n<h2>\u0424\u0435\u0439\u0434 UIView<\/h2>\n<figure class=\"\"><\/figure>\n<p>\u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e: \u0430\u043b\u044c\u0444\u0430\u00a0<strong>UIView <\/strong>&#8212; \u044d\u0442\u043e<strong> <\/strong>\u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"swift\">\/\/ \u041f\u0440\u043e\u0446\u0435\u043d\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 let animationCompletionPercent = (maxConstraintConstant - currentConstraintConstant) \/ (maxConstraintConstant - minConstraintConstant) fadeView.alpha = animationCompletionPercent<\/code><\/pre>\n<h2>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 UIView<\/h2>\n<figure class=\"\"><\/figure>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u0444\u0444\u0438\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438. \u0414\u0432\u0443\u0445\u043c\u0435\u0440\u043d\u044b\u0435 \u0430\u0444\u0444\u0438\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043d\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 3&#215;3, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0439, \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0430\u043d\u0443\u0442 \u043d\u043e\u0432\u044b\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0438. \u0415\u0441\u043b\u0438 \u0432\u043a\u0440\u0430\u0442\u0446\u0435, \u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u0444\u0444\u0438\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0439\u00a0<strong>UIView<\/strong>\u00a0\u043c\u043e\u0436\u043d\u043e \u0434\u0432\u0438\u0433\u0430\u0442\u044c, \u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0443\u0433\u043e\u0434\u043d\u043e. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c\u00a0<strong>UIViewPropertyAnimator<\/strong>\u00a0\u0434\u043b\u044f \u0430\u043d\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\u00a0<strong>UIView<\/strong>.<\/p>\n<pre><code class=\"swift\">class CoordinatesChangeView: UIView {     var animationCompletionPercentage: Double = 0 {         didSet { animator.fractionComplete = animationCompletionPercentage }     }  private let side: CGFloat = 60  private lazy var animator = UIViewPropertyAnimator(duration: 0.1, curve: .easeIn) { [weak self] in         guard let self else { return }          self.imageView.transform = CGAffineTransform(translationX: self.side - self.bounds.width, y: 0)     } }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438\u00a0<strong>CoordinatesChangeView<\/strong>. \u0412 \u0441\u0430\u043c\u043e\u043c\u00a0<strong>UIViewController<\/strong>\u00a0\u0432\u0441\u0451 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435:<\/p>\n<pre><code class=\"swift\">\/\/ \u041f\u0440\u043e\u0446\u0435\u043d\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 let animationCompletionPercent = (maxConstraintConstant - currentConstraintConstant) \/ (maxConstraintConstant - minConstraintConstant) coordinateChangeView.animationCompletionPercentage = animationCompletionPercent<\/code><\/pre>\n<h2>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 UIView<\/h2>\n<figure class=\"\"><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0444\u0444\u0438\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0430\u043d\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437\u00a0<strong>UIViewPropertyAnimator<\/strong>, \u043d\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u043c, \u0430 \u0441\u0430\u043c\u0438\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0435\u0439\u043d\u0442\u043e\u043c:<\/p>\n<pre><code class=\"swift\">private let minConstraintConstant: CGFloat = 50 private let maxConstraintConstant: CGFloat = 200  private var animatedConstraint: NSLayoutConstraint? private var avatarHeightConstraint: NSLayoutConstraint?  private func setupAvatarView() { view.addSubview(avatarImageView)              avatarHeightConstraint = avatarImageView.heightAnchor.constraint(equalToConstant: maxConstraintConstant)              NSLayoutConstraint.activate([ avatarHeightConstraint!,         avatarImageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),         avatarImageView.heightAnchor.constraint(equalTo: avatarImageView.widthAnchor, multiplier: 1.0),         avatarImageView.centerXAnchor.constraint(equalTo: view.centerXAnchor), ]) }<\/code><\/pre>\n<p>\u0412 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435 \u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 \u0438 \u0431\u0443\u0434\u0443 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0451 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435\u00a0<strong>scrollViewDidScroll:<\/strong><\/p>\n<pre><code>\/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u0432\u044b\u0441\u043e\u0442\u0443 \u0438 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u043c \u0441\u043a\u0440\u043e\u043b\u043b, \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b if newConstraintConstant != currentConstraintConstant { animatedConstraint?.constant = newConstraintConstant     scrollView.contentOffset.y = previousContentOffsetY }          \/\/ \u041c\u0435\u043d\u044f\u0435\u043c \u0432\u044b\u0441\u043e\u0442\u0443 \u0430\u0432\u0430\u0442\u0430\u0440\u0430, \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b if newConstraintConstant != avatarHeightConstraint!.constant { avatarHeightConstraint?.constant = currentConstraintConstant }<\/code><\/pre>\n<p>\u0418\u0437\u043c\u0435\u043d\u044f\u044e \u0432\u044b\u0441\u043e\u0442\u0443 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0441 \u043a\u043e\u0441\u043d\u0442\u0440\u0435\u0439\u043d\u0442\u043e\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u044b &#8212; \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041c\u043d\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u043d\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u044f \u043c\u0435\u043d\u044f\u044e \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u0443 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u043d\u043e, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439. \u042f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0443 \u0432\u0430\u0441 \u0431\u044b\u043b\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0438\u0449\u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u0439. \u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0437\u0434\u0435\u0441\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a\u043e\u0434\u0430. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443\u0442\u044c, \u0447\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043b\u0430\u0434\u0435\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u043d\u043e \u0438 \u0443\u043c\u0435\u0442\u044c \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/723386\/\"> https:\/\/habr.com\/ru\/post\/723386\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-346976","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/346976","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=346976"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/346976\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=346976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=346976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=346976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}