{"id":321017,"date":"2021-04-07T09:00:25","date_gmt":"2021-04-07T09:00:25","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=321017"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=321017","title":{"rendered":"\u041d\u0430\u0441\u0442\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0444\u0438\u0433\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0440\u0438\u0439. \u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0442\u0440\u0430\u043d\u0437\u0438\u0448\u0435\u043d\u044b \u0432 iOS. [2\/2]"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d90\/186\/a08\/d90186a0833fce07dfa038d698a97548.png\" width=\"1200\" height=\"726\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/company\/citymobil\/blog\/549284\/\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044e ZoomIn\/ZoomOut \u0434\u043b\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u044d\u043a\u0440\u0430\u043d\u0430 \u0441 \u0438\u0441\u0442\u043e\u0440\u0438\u044f\u043c\u0438.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u043f\u0440\u043e\u043a\u0430\u0447\u0430\u0435\u043c <code>StoryBaseViewController<\/code> \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u0442\u043e\u0440\u0438\u044f\u043c\u0438.<\/p>\n<h4>\u041d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u0442\u043e\u0440\u0438\u044f\u043c\u0438<\/h4>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u0442\u043e\u0440\u0438\u044f\u043c\u0438.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4da\/d6e\/fe6\/4dad6efe644e523578169b4b9357345d.gif\" width=\"384\" height=\"848\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"swift\">enum TransitionOperation {     case push, pop }  public class StoryBaseViewController: UIViewController {          \/\/ MARK: - Constants     private enum Spec {         static let minVelocityToHide: CGFloat = 1500                  enum CloseImage {             static let size: CGSize = CGSize(width: 40, height: 40)             static var original: CGPoint = CGPoint(x: 24, y: 50)         }     }          \/\/ MARK: - UI components     private lazy var closeButton: UIButton = {         let button = UIButton(type: .custom)         button.setImage(#imageLiteral(resourceName: \"close\"), for: .normal)         button.addTarget(self, action: #selector(closeButtonAction(sender:)), for: .touchUpInside)         button.frame = CGRect(origin: Spec.CloseImage.original, size: Spec.CloseImage.size)         return button     }()          \/\/ MARK: - Private properties     \/\/ 1     private lazy var percentDrivenInteractiveTransition: UIPercentDrivenInteractiveTransition? = nil     private lazy var operation: TransitionOperation? = nil          \/\/ MARK: - Lifecycle     public override func loadView() {         super.loadView()         setupUI()     }      }  extension StoryBaseViewController {          private func setupUI() {         \/\/ 2         let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))         panGestureRecognizer.delegate = self         view.addGestureRecognizer(panGestureRecognizer)         view.addSubview(closeButton)     }          @objc     private func closeButtonAction(sender: UIButton!) {         dismiss(animated: true, completion: nil)     }      }  \/\/ MARK: UIPanGestureRecognizer extension StoryBaseViewController: UIGestureRecognizerDelegate {          @objc     func handlePanGesture(_ panGesture: UIPanGestureRecognizer) {         handleHorizontalSwipe(panGesture: panGesture)     }          \/\/ 3     private func handleHorizontalSwipe(panGesture: UIPanGestureRecognizer) {                  let velocity = panGesture.velocity(in: view)         \/\/ 4 \u041e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0441\u0432\u0430\u0439\u043f\u0430 \u043f\u043e \u044d\u043a\u0440\u0430\u043d\u0443, \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 0 \u0434\u043e 1         var percent: CGFloat {             switch operation {             case .push:                 return abs(min(panGesture.translation(in: view).x, 0)) \/ view.frame.width                              case .pop:                 return max(panGesture.translation(in: view).x, 0) \/ view.frame.width                              default:                 return max(panGesture.translation(in: view).x, 0) \/ view.frame.width             }         }                  \/\/ 5         switch panGesture.state {         case .began:             \/\/ 6             percentDrivenInteractiveTransition = UIPercentDrivenInteractiveTransition()             percentDrivenInteractiveTransition?.completionCurve = .easeOut                          navigationController?.delegate = self             if velocity.x &gt; 0 {                 operation = .pop                 navigationController?.popViewController(animated: true)             } else {                 operation = .push                                  let nextVC = StoryBaseViewController()                 nextVC.view.backgroundColor = UIColor.random                 navigationController?.pushViewController(nextVC, animated: true)             }                      case .changed:             \/\/ 7             percentDrivenInteractiveTransition?.update(percent)                      case .ended:             \/\/ 8             if percent &gt; 0.5 || velocity.x &gt; Spec.minVelocityToHide {                 percentDrivenInteractiveTransition?.finish()             } else {                 percentDrivenInteractiveTransition?.cancel()             }             percentDrivenInteractiveTransition = nil             navigationController?.delegate = nil                      case .cancelled, .failed:             \/\/ 9             percentDrivenInteractiveTransition?.cancel()             percentDrivenInteractiveTransition = nil             navigationController?.delegate = nil                      default:             break         }     }      }<\/code><\/pre>\n<ol>\n<li>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0448\u0430 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0430 \u0437\u0430 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435\u043c \u043f\u0430\u043b\u044c\u0446\u0430, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 <code>percentDrivenInteractiveTransition<\/code>. \u0410 <code>operation<\/code> \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 (<code>push<\/code> \u0438\u043b\u0438 <code>pop<\/code>).<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0448 \u0436\u0435\u0441\u0442 \u0432\u043e view.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430\u0436\u0430\u0442\u0438\u044f\/\u0441\u0432\u0430\u0439\u043f\u0430.<\/p>\n<\/li>\n<li>\n<p><code>percent<\/code> \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0441\u0432\u0430\u0439\u043f\u0430 \u043f\u043e \u044d\u043a\u0440\u0430\u043d\u0443 \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 0 \u0434\u043e 1.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0436\u0435\u0441\u0442\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u0436\u0435\u0441\u0442, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0432\u0435\u0436\u0438\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>UIPercentDrivenInteractiveTransition<\/code> \u0438 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u043c \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0443 <code>navigationController<\/code>\u2019\u0430, \u0447\u0442\u043e \u043c\u044b \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c (\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043d\u0438\u0436\u0435). \u0415\u0441\u043b\u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u0430\u0439\u043f\u0430 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435, \u0442\u043e \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>operation<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435&nbsp;<code>.pop<\/code>, \u0438 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u043c <code>navigationController<\/code>\u2019\u0443, \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u0447\u0430\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0441 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0435\u0439 <code>.navigationController?.popViewController(animated: true)<\/code>. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0434\u043b\u044f&nbsp;<code>.push<\/code>-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043d\u0430\u0448 \u0441\u0432\u0430\u0439\u043f \u0443\u0436\u0435 \u0430\u043a\u0442\u0438\u0432\u0435\u043d, \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0435\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0432 <code>percentDrivenInteractiveTransition<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u043e\u0441\u0432\u0430\u0439\u043f\u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u044b \u044d\u043a\u0440\u0430\u043d\u0430, \u0438\u043b\u0438 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0441 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e \u0431\u043e\u043b\u0435\u0435 1500, \u0442\u043e \u043c\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 <code>percentDrivenInteractiveTransition?.finish()<\/code><em>.<\/em> \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c <code>percentDrivenInteractiveTransition<\/code> \u0438 <code>navigationController?.delegate<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u043c\u0435\u043d\u044b \u0441\u0432\u0430\u0439\u043f\u0430 \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0438 \u043e\u0447\u0438\u0449\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ol>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u0438 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0432\u0430\u0439\u043f\u0430 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c <code>navigationController<\/code>\u2019\u0443, \u0447\u0442\u043e \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0434\u0435\u043b\u0435\u0433\u0430\u0442 <code>navigationController?.delegate = self<\/code>. \u041d\u043e \u043c\u044b \u044d\u0442\u043e\u0433\u043e \u0442\u0430\u043a \u0438 \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438. \u0421\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f:<\/p>\n<pre><code class=\"swift\">\/\/ MARK: UINavigationControllerDelegate     extension StoryBaseViewController: UINavigationControllerDelegate {          \/\/ 1     public func navigationController(         _ navigationController: UINavigationController,         animationControllerFor operation: UINavigationController.Operation,         from fromVC: UIViewController,         to toVC: UIViewController     ) -&gt; UIViewControllerAnimatedTransitioning? {                  switch operation {         case .push:             return StoryBaseAnimatedTransitioning(operation: .push)                      case .pop:             return StoryBaseAnimatedTransitioning(operation: .pop)                      default:             return nil         }     }          \/\/ 2     public func navigationController(         _ navigationController: UINavigationController,         interactionControllerFor animationController: UIViewControllerAnimatedTransitioning     ) -&gt; UIViewControllerInteractiveTransitioning? {              return percentDrivenInteractiveTransition     }      }<\/code><\/pre>\n<ol>\n<li>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>UIPercentDrivenInteractiveTransition<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430.<\/p>\n<\/li>\n<\/ol>\n<h4>\u0410\u043d\u0438\u043c\u0430\u0442\u043e\u0440<\/h4>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430.<\/p>\n<p>\u041d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0435 \u0437\u0430 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 \u0438 \u0441\u0430\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434.<\/p>\n<pre><code class=\"swift\">class StoryBaseAnimatedTransitioning: NSObject {          private enum Spec {         static let animationDuration: TimeInterval = 0.3         static let cornerRadius: CGFloat = 10         static let minimumScale = CGAffineTransform(scaleX: 0.85, y: 0.85)     }          private let operation: TransitionOperation          init(operation: TransitionOperation) {         self.operation = operation     }      }  extension StoryBaseAnimatedTransitioning: UIViewControllerAnimatedTransitioning {          \/\/ http:\/\/fusionblender.net\/swipe-transition-between-uiviewcontrollers\/     func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {                  \/\/\/ 1 \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c view-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0435\u043c \u0430\u043d\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c.         guard             let fromViewController = transitionContext.viewController(forKey: .from),             let toViewController = transitionContext.viewController(forKey: .to)         else {             return         }                  \/\/\/ 2 \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044e, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f (\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435).         let containerView = transitionContext.containerView         containerView.backgroundColor = UIColor.clear                  \/\/\/ 3 \u0417\u0430\u043a\u0440\u0443\u0433\u043b\u044f\u0435\u043c \u0443\u0433\u043b\u044b \u043d\u0430\u0448\u0438\u0445 view \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435.         fromViewController.view.layer.masksToBounds = true         fromViewController.view.layer.cornerRadius = Spec.cornerRadius         toViewController.view.layer.masksToBounds = true         toViewController.view.layer.cornerRadius = Spec.cornerRadius                  \/\/\/ 4 \u041e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0448\u0438\u0440\u0438\u043d\u0443 containerView         \/\/ Swipe progress == width         let width = containerView.frame.width          \/\/\/ 5 \u041d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 fromViewController.view (\u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0432\u0438\u0434\u0438\u043c\u044b\u0439 VC)         var offsetLeft = fromViewController.view.frame          \/\/\/ 6 \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f fromViewController \u0438 toViewController         switch operation {         case .push:             offsetLeft.origin.x = 0             toViewController.view.frame.origin.x = width             toViewController.view.transform = .identity                      case .pop:             offsetLeft.origin.x = width             toViewController.view.frame.origin.x = 0             toViewController.view.transform = Spec.minimumScale         }                  \/\/\/ 7 \u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c toViewController.view \u043d\u0430\u0434\/\u043f\u043e\u0434 fromViewController.view, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0440\u0430\u043d\u0437\u0438\u0448\u0435\u043d\u0430         switch operation {         case .push:             containerView.insertSubview(toViewController.view, aboveSubview: fromViewController.view)                      case .pop:             containerView.insertSubview(toViewController.view, belowSubview: fromViewController.view)         }                  \/\/ \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0443\u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438, \u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u043d\u0435\u0439         let duration = self.transitionDuration(using: transitionContext)                  UIView.animate(withDuration: duration, delay: 0, options: .curveEaseIn, animations: {                      \/\/\/ 8. \u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 view-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 \u0438 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0438\u0445.             let moveViews = {                 toViewController.view.frame = fromViewController.view.frame                 fromViewController.view.frame = offsetLeft             }              switch self.operation {             case .push:                 moveViews()                 toViewController.view.transform = .identity                 fromViewController.view.transform = Spec.minimumScale                              case .pop:                 toViewController.view.transform = .identity                 fromViewController.view.transform = .identity                 moveViews()             }                      }, completion: { _ in                          \/\/\/9.  \u0423\u0431\u0438\u0440\u0430\u0435\u043c \u043b\u044e\u0431\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438 \u0441\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u0438\u044f             toViewController.view.transform = .identity             fromViewController.view.transform = .identity                          fromViewController.view.layer.masksToBounds = true             fromViewController.view.layer.cornerRadius = 0             toViewController.view.layer.masksToBounds = true             toViewController.view.layer.cornerRadius = 0                   \/\/\/ 10. \u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0431\u044b\u043b \u043e\u0442\u043c\u0435\u043d\u0435\u043d, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0432\u0441\u0451 \u0442\u043e, \u0447\u0442\u043e \u0443\u0441\u043f\u0435\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0422\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c toViewController.view \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430.             if transitionContext.transitionWasCancelled {                 toViewController.view.removeFromSuperview()             }                          containerView.backgroundColor = .clear             \/\/\/ 11. \u0421\u043e\u043e\u0431\u0449\u0430\u0435\u043c transitionContext \u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438             transitionContext.completeTransition(!transitionContext.transitionWasCancelled)         })              }          \/\/ 12. \u0412\u0440\u0435\u043c\u044f \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438     func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -&gt; TimeInterval {         return Spec.animationDuration     }<\/code><\/pre>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c view-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0435\u043c \u0430\u043d\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044e <code>containerView<\/code>, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f (\u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0432 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435).<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043a\u0440\u0443\u0433\u043b\u044f\u0435\u043c \u0443\u0433\u043b\u044b \u043d\u0430\u0448\u0438\u0445 view \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435.<\/p>\n<\/li>\n<li>\n<p><code>width<\/code> \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u043f\u0440\u0438 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 \u0437\u0430 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0448\u0438\u0440\u0438\u043d\u0443 <code>containerView<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>offsetLeft<\/code> \u2014 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <code>fromViewController<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u044d\u043a\u0440\u0430\u043d\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c <code>toViewController.view<\/code> \u043d\u0430\u0434\/\u043f\u043e\u0434 <code>fromViewController.view<\/code>, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 view-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 \u0438 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0438\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0423\u0431\u0438\u0440\u0430\u0435\u043c \u043b\u044e\u0431\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438 \u0441\u043a\u0440\u0443\u0433\u043b\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0431\u044b\u043b \u043e\u0442\u043c\u0435\u043d\u0435\u043d, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0432\u0441\u0451 \u0442\u043e, \u0447\u0442\u043e \u0443\u0441\u043f\u0435\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0422\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c <code>toViewController.view<\/code> \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u043e\u0431\u0449\u0430\u0435\u043c <code>transitionContext<\/code> \u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u0441\u0451, \u043d\u0430\u0448 \u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440 \u0433\u043e\u0442\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u043d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0435\u043c\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c. \u0410\u043d\u0438\u043c\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d91\/9a5\/fa1\/d919a5fa13f0a990ad25d49726724a90.gif\" width=\"708\" height=\"1280\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0435\u0441\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442\u0435 <a href=\"https:\/\/github.com\/mapmelad\/StoriesNavigationPt2\">\u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0442\u0443\u0442.<\/a> \u0411\u0443\u0434\u0443 \u0440\u0430\u0434 \u0432\u0430\u0448\u0438\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c \u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f\u043c!<\/p>\n<\/div>\n<p> \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\/company\/citymobil\/blog\/549288\/\"> https:\/\/habr.com\/ru\/company\/citymobil\/blog\/549288\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/company\/citymobil\/blog\/549284\/\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044e ZoomIn\/ZoomOut \u0434\u043b\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u044d\u043a\u0440\u0430\u043d\u0430 \u0441 \u0438\u0441\u0442\u043e\u0440\u0438\u044f\u043c\u0438.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u043f\u0440\u043e\u043a\u0430\u0447\u0430\u0435\u043c <code>StoryBaseViewController<\/code> \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u0442\u043e\u0440\u0438\u044f\u043c\u0438.<\/p>\n<h4>\u041d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u0442\u043e\u0440\u0438\u044f\u043c\u0438<\/h4>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0438\u0441\u0442\u043e\u0440\u0438\u044f\u043c\u0438.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"swift\">enum TransitionOperation {     case push, pop }  public class StoryBaseViewController: UIViewController {          \/\/ MARK: - Constants     private enum Spec {         static let minVelocityToHide: CGFloat = 1500                  enum CloseImage {             static let size: CGSize = CGSize(width: 40, height: 40)             static var original: CGPoint = CGPoint(x: 24, y: 50)         }     }          \/\/ MARK: - UI components     private lazy var closeButton: UIButton = {         let button = UIButton(type: .custom)         button.setImage(#imageLiteral(resourceName: \"close\"), for: .normal)         button.addTarget(self, action: #selector(closeButtonAction(sender:)), for: .touchUpInside)         button.frame = CGRect(origin: Spec.CloseImage.original, size: Spec.CloseImage.size)         return button     }()          \/\/ MARK: - Private properties     \/\/ 1     private lazy var percentDrivenInteractiveTransition: UIPercentDrivenInteractiveTransition? = nil     private lazy var operation: TransitionOperation? = nil          \/\/ MARK: - Lifecycle     public override func loadView() {         super.loadView()         setupUI()     }      }  extension StoryBaseViewController {          private func setupUI() {         \/\/ 2         let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))         panGestureRecognizer.delegate = self         view.addGestureRecognizer(panGestureRecognizer)         view.addSubview(closeButton)     }          @objc     private func closeButtonAction(sender: UIButton!) {         dismiss(animated: true, completion: nil)     }      }  \/\/ MARK: UIPanGestureRecognizer extension StoryBaseViewController: UIGestureRecognizerDelegate {          @objc     func handlePanGesture(_ panGesture: UIPanGestureRecognizer) {         handleHorizontalSwipe(panGesture: panGesture)     }          \/\/ 3     private func handleHorizontalSwipe(panGesture: UIPanGestureRecognizer) {                  let velocity = panGesture.velocity(in: view)         \/\/ 4 \u041e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0441\u0432\u0430\u0439\u043f\u0430 \u043f\u043e \u044d\u043a\u0440\u0430\u043d\u0443, \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 0 \u0434\u043e 1         var percent: CGFloat {             switch operation {             case .push:                 return abs(min(panGesture.translation(in: view).x, 0)) \/ view.frame.width                              case .pop:                 return max(panGesture.translation(in: view).x, 0) \/ view.frame.width                              default:                 return max(panGesture.translation(in: view).x, 0) \/ view.frame.width             }         }                  \/\/ 5         switch panGesture.state {         case .began:             \/\/ 6             percentDrivenInteractiveTransition = UIPercentDrivenInteractiveTransition()             percentDrivenInteractiveTransition?.completionCurve = .easeOut                          navigationController?.delegate = self             if velocity.x &gt; 0 {                 operation = .pop                 navigationController?.popViewController(animated: true)             } else {                 operation = .push                                  let nextVC = StoryBaseViewController()                 nextVC.view.backgroundColor = UIColor.random                 navigationController?.pushViewController(nextVC, animated: true)             }                      case .changed:             \/\/ 7             percentDrivenInteractiveTransition?.update(percent)                      case .ended:             \/\/ 8             if percent &gt; 0.5 || velocity.x &gt; Spec.minVelocityToHide {                 percentDrivenInteractiveTransition?.finish()             } else {                 percentDrivenInteractiveTransition?.cancel()             }             percentDrivenInteractiveTransition = nil             navigationController?.delegate = nil                      case .cancelled, .failed:             \/\/ 9             percentDrivenInteractiveTransition?.cancel()             percentDrivenInteractiveTransition = nil             navigationController?.delegate = nil                      default:             break         }     }      }<\/code><\/pre>\n<ol>\n<li>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0448\u0430 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0430 \u0437\u0430 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435\u043c \u043f\u0430\u043b\u044c\u0446\u0430, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 <code>percentDrivenInteractiveTransition<\/code>. \u0410 <code>operation<\/code> \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 (<code>push<\/code> \u0438\u043b\u0438 <code>pop<\/code>).<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0448 \u0436\u0435\u0441\u0442 \u0432\u043e view.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430\u0436\u0430\u0442\u0438\u044f\/\u0441\u0432\u0430\u0439\u043f\u0430.<\/p>\n<\/li>\n<li>\n<p><code>percent<\/code> \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0441\u0432\u0430\u0439\u043f\u0430 \u043f\u043e \u044d\u043a\u0440\u0430\u043d\u0443 \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043e\u0442 0 \u0434\u043e 1.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0436\u0435\u0441\u0442\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u0436\u0435\u0441\u0442, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0432\u0435\u0436\u0438\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>UIPercentDrivenInteractiveTransition<\/code> \u0438 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u043c \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0443 <code>navigationController<\/code>\u2019\u0430, \u0447\u0442\u043e \u043c\u044b \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c (\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043d\u0438\u0436\u0435). \u0415\u0441\u043b\u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u0430\u0439\u043f\u0430 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435, \u0442\u043e \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>operation<\/code> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435&nbsp;<code>.pop<\/code>, \u0438 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u043c <code>navigationController<\/code>\u2019\u0443, \u0447\u0442\u043e \u043c\u044b \u043d\u0430\u0447\u0430\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0441 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0435\u0439 <code>.navigationController?.popViewController(animated: true)<\/code>. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0434\u043b\u044f&nbsp;<code>.push<\/code>-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043d\u0430\u0448 \u0441\u0432\u0430\u0439\u043f \u0443\u0436\u0435 \u0430\u043a\u0442\u0438\u0432\u0435\u043d, \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0435\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0432 <code>percentDrivenInteractiveTransition<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u0440\u043e\u0441\u0432\u0430\u0439\u043f\u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u044b \u044d\u043a\u0440\u0430\u043d\u0430, \u0438\u043b\u0438 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0441 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e \u0431\u043e\u043b\u0435\u0435 1500, \u0442\u043e \u043c\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 <code>percentDrivenInteractiveTransition?.finish()<\/code><em>.<\/em> \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c <code>percentDrivenInteractiveTransition<\/code> \u0438 <code>navigationController?.delegate<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0442\u043c\u0435\u043d\u044b \u0441\u0432\u0430\u0439\u043f\u0430 \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0438 \u043e\u0447\u0438\u0449\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ol>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u0438 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0432\u0430\u0439\u043f\u0430 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0438\u0442\u044c <code>navigationController<\/code>\u2019\u0443, \u0447\u0442\u043e \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0434\u0435\u043b\u0435\u0433\u0430\u0442 <code>navigationController?.delegate = self<\/code>. \u041d\u043e \u043c\u044b \u044d\u0442\u043e\u0433\u043e \u0442\u0430\u043a \u0438 \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438. \u0421\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f:<\/p>\n<pre><code class=\"swift\">\/\/ MARK: UINavigationControllerDelegate     extension StoryBaseViewController: UINavigationControllerDelegate {          \/\/ 1     public func navigationController(         _ navigationController: UINavigationController,         animationControllerFor operation: UINavigationController.Operation,         from fromVC: UIViewController,         to toVC: UIViewController     ) -&gt; UIViewControllerAnimatedTransitioning? {                  switch operation {         case .push:             return StoryBaseAnimatedTransitioning(operation: .push)                      case .pop:             return StoryBaseAnimatedTransitioning(operation: .pop)                      default:             return nil         }     }          \/\/ 2     public func navigationController(         _ navigationController: UINavigationController,         interactionControllerFor animationController: UIViewControllerAnimatedTransitioning     ) -&gt; UIViewControllerInteractiveTransitioning? {              return percentDrivenInteractiveTransition     }      }<\/code><\/pre>\n<ol>\n<li>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>UIPercentDrivenInteractiveTransition<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430.<\/p>\n<\/li>\n<\/ol>\n<h4>\u0410\u043d\u0438\u043c\u0430\u0442\u043e\u0440<\/h4>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0430\u043d\u0438\u043c\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430.<\/p>\n<p>\u041d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0435 \u0437\u0430 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438 \u0438 \u0441\u0430\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434.<\/p>\n<pre><code class=\"swift\">class StoryBaseAnimatedTransitioning: NSObject {          private enum Spec {         static let animationDuration: TimeInterval = 0.3         static let cornerRadius: CGFloat = 10         static let minimumScale = CGAffineTransform(scaleX: 0.85, y: 0.85)     }          private let operation: TransitionOperation          init(operation: TransitionOperation) {         self.operation = operation     }      }  extension StoryBaseAnimatedTransitioning: UIViewControllerAnimatedTransitioning {          \/\/ http:\/\/fusionblender.net\/swipe-transition-between-uiviewcontrollers\/     func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {                  \/\/\/ 1 \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c view-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0435\u043c \u0430\u043d\u0438\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c.         guard             let fromViewController = transitionContext.viewController(forKey: .from),             let toViewController = transitionContext.viewController(forKey: .to)         else {             return         }                  \/\/\/ 2 \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044e, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044f (\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435).         let containerView = transitionContext.containerView         containerView.backgroundColor = UIColor.clear                  \/\/\/ 3 \u0417\u0430\u043a\u0440\u0443\u0433\u043b\u044f\u0435\u043c \u0443\u0433\u043b\u044b \u043d\u0430\u0448\u0438\u0445 view \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435.         fromViewController.view.layer.masksToBounds = true         fromViewController.view.layer.cornerRadius = Spec.cornerRadius         toViewController.view.layer.masksToBounds = true         toViewController.view.layer.cornerRadius = Spec.cornerRadius                  \/\/\/ 4 \u041e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0448\u0438\u0440\u0438\u043d\u0443 containerView         \/\/ Swipe progress == width         let width = containerView.frame.width          \/\/\/ 5 \u041d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 fromViewController.view (\u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0432\u0438\u0434\u0438\u043c\u044b\u0439 VC)         var offsetLeft = fromViewController.view.frame          \/\/\/ 6 \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f fromViewController \u0438 toViewController         switch operation {         case .push:             offsetLeft.origin.x = 0             toViewController.view.frame.origin.x = width             toViewController.view.transform = .identity                      case .pop:             offsetLeft.origin.x = width             toViewController.view.frame.origin.x = 0             toViewController.view.transform = Spec.minimumScale         }                  \/\/\/ 7 \u041f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0435\u043c toViewController.view \u043d\u0430\u0434\/\u043f\u043e\u0434 fromViewController.view, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0440\u0430\u043d\u0437\u0438\u0448\u0435\u043d\u0430         switch operation {         case .push:<\/code><\/pre>\n<\/div>\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-321017","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/321017","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=321017"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/321017\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}