### Sample Gesture Recognizer Handler for Interactive Transitions Source: https://github.com/herotransitions/hero/wiki/Interactive-Transition An example of how to integrate Hero's interactive transition methods within a gesture recognizer's handler. ```APIDOC ## Sample Gesture Recognizer Handler ### Description This example demonstrates a gesture recognizer handler that utilizes Hero's interactive transition methods to manage a transition based on user gestures. ### Method ```swift func pan() { let translation = panGR.translation(in: nil) let progress = translation.y / 2 / collectionView!.bounds.height switch panGR.state { case .began: Hero.shared.setDefaultAnimationForNextTransition(.fade) hero_dismissViewController() case .changed: Hero.shared.update(progress: Double(progress)) if let cell = collectionView?.visibleCells[0] as? ScrollingImageCell { let currentPos = CGPoint(x: translation.x + view.center.x, y: translation.y + view.center.y) Hero.shared.apply(modifiers: [.position(currentPos)], to: cell.imageView) } default: if progress + panGR.velocity(in: nil).y / collectionView!.bounds.height > 0.3 { Hero.shared.end() } else { Hero.shared.cancel() } } } ``` ### Explanation - **.began**: Initiates the transition, often by calling `hero_dismissViewController` or `hero_presentViewController`, and sets a default animation. - **.changed**: Updates the transition progress using `Hero.shared.update(progress:)` and can apply custom modifiers to views using `Hero.shared.apply(modifiers:to:)` as the gesture changes. - **default**: Determines whether to end or cancel the transition based on the gesture's final progress and velocity. Calls `Hero.shared.end()` or `Hero.shared.cancel()` accordingly. ``` -------------------------------- ### Carthage Installation Source: https://github.com/herotransitions/hero/blob/develop/docs/index.html Steps to integrate the Hero library using Carthage. Add the Hero repository to your Cartfile, run 'carthage update', and then manually link the framework to your project. Follow Carthage's documentation for additional project setup. ```shell github "HeroTransitions/Hero" carthage update ``` -------------------------------- ### Install Hero with Carthage Source: https://github.com/herotransitions/hero/blob/develop/README.md Integrate Hero using Carthage by adding the framework to your Cartfile and running carthage update. If this is your first time using Carthage, follow the additional setup steps provided by Carthage. ```text github "HeroTransitions/Hero" ``` -------------------------------- ### CocoaPods Installation Source: https://github.com/herotransitions/hero/blob/develop/docs/docsets/Hero.docset/Contents/Resources/Documents/index.html Instructions for installing the Hero library using CocoaPods. Add 'pod 'Hero'' to your Podfile and run 'pod install'. Remember to import Hero in your Swift files. ```ruby pod 'Hero' ``` -------------------------------- ### CocoaPods Installation Source: https://github.com/herotransitions/hero/blob/develop/docs/index.html Instructions for installing the Hero library using CocoaPods. This involves adding the 'Hero' pod to your Podfile and running the 'pod install' command. Remember to import Hero in your Swift files. ```shell pod 'Hero' pod install import Hero ``` -------------------------------- ### Accio Installation Source: https://github.com/herotransitions/hero/blob/develop/docs/index.html Guidance on adding Hero as a dependency using Accio. This involves specifying the Hero package in your Package.swift file and adding it to your target's dependencies. Then, run 'accio update'. ```swift .package(url: "https://github.com/HeroTransitions/Hero.git", .upToNextMajor(from: "1.4.0")) .target( name: "App", dependencies: [ "Hero", ] ) accio update ``` -------------------------------- ### Manually Install Hero Source: https://github.com/herotransitions/hero/blob/develop/README.md Manually add the Hero library to your project by dragging the 'Sources' folder directly into your project structure. ```text - Drag the **Sources** folder anywhere in your project. ``` -------------------------------- ### Hero.shared - Interactive Transition Management Source: https://github.com/herotransitions/hero/wiki/Interactive-Transition The `Hero.shared` singleton object provides methods to control the progress, update animations, and apply modifiers during an interactive transition. ```APIDOC ## Hero.shared Interactive Transition Methods ### Description Provides methods to manage the state and appearance of views during interactive transitions. ### Methods - **update(progress:)** Updates the progress of the current interactive transition. - **Parameters**: - **progress** (Double) - Required - The current progress of the transition, must be between 0 and 1. - **end(animate:)** Finishes the interactive transition, animating from the current state to the end state. - **Parameters**: - **animate** (Bool) - Optional - Defaults to true. Whether to animate the transition to the end state. - **cancel(animate:)** Cancels the interactive transition, animating from the current state back to the beginning state. - **Parameters**: - **animate** (Bool) - Optional - Defaults to true. Whether to animate the transition back to the beginning state. - **apply(modifiers:to:)** Overrides modifiers for a specific view during an interactive animation. - **Parameters**: - **modifiers** ([HeroModifier]) - Required - The list of modifiers to apply. - **view** (UIView) - Required - The view to apply the modifiers to. ### Request Example (Applying modifiers) ```json { "example": "Hero.shared.apply([.position(x: 50, y: 50)], to: someView)" } ``` ### Response Example (N/A) This method does not return a value. ``` -------------------------------- ### Install Hero with CocoaPods (Ruby) Source: https://github.com/herotransitions/hero/blob/develop/README.md This code snippet shows how to add the Hero library as a dependency to your iOS project using CocoaPods. After adding the 'pod 'Hero'' line to your Podfile, run 'pod install' in your terminal. ```ruby pod 'Hero' ``` -------------------------------- ### Example of .selectBy Animation Type Usage Source: https://github.com/herotransitions/hero/wiki/Default-Animations Demonstrates how to use the `.selectBy` animation type to specify different animations for presenting and dismissing view controllers. This allows for distinct transition behaviors based on the action being performed. ```swift .selectBy(presenting:.push(.left), dismissing:.pull(.right)) ``` -------------------------------- ### Install Hero with Accio Source: https://github.com/herotransitions/hero/blob/develop/README.md Add Hero to your project using Accio by specifying the package URL and version in your Package.swift file. Then, include 'Hero' in your App target's dependencies and run 'accio update'. ```swift .package(url: "https://github.com/HeroTransitions/Hero.git", .upToNextMajor(from: "1.4.0")), ``` ```swift .target( name: "App", dependencies: [ "Hero", ] ), ``` -------------------------------- ### Swift Package Manager Installation Source: https://github.com/herotransitions/hero/blob/develop/docs/index.html Instructions for integrating Hero using Swift Package Manager. Add the Hero repository URL to your Package.swift file as a dependency and specify 'Hero' in your target's dependencies. This method is compatible with Xcode 11+. ```swift // swift-tools-version:4.0 import PackageDescription let package = Package( name: "MyPackage", products: [ .library( name: "MyPackage", targets: ["MyPackage"]), ], dependencies: [ .package(url: "https://github.com/HeroTransitions/Hero.git", .upToNextMajor(from: "1.6.3")) ], targets: [ .target( name: "MyPackage", dependencies: ["Hero"]) ] ) ``` -------------------------------- ### Swift Package Manager Dependency Declaration Source: https://github.com/herotransitions/hero/wiki/Installation This code snippet shows how to declare the Hero library as a dependency in your Swift Package Manager `Package.swift` file. It specifies the URL of the GitHub repository. Ensure the URL is correct for the desired version. ```swift import PackageDescription let package = Package( name: "NameOfYourPackage", dependencies: [ .Package(url: "https://github.com/lkzhao/Hero") ] ) ``` -------------------------------- ### Install Hero with Swift Package Manager Source: https://github.com/herotransitions/hero/blob/develop/README.md Integrate Hero using Swift Package Manager by adding the repository URL to your Package.swift file's dependencies. Specify 'Hero' as a dependency in the target where you intend to use it. ```swift .package(url: "https://github.com/HeroTransitions/Hero.git", .upToNextMajor(from: "1.3.0")) ``` ```swift // swift-tools-version:4.0 import PackageDescription let package = Package( name: "MyPackage", products: [ .library( name: "MyPackage", targets: ["MyPackage"]), ], dependencies: [ .package(url: "https://github.com/HeroTransitions/Hero.git", .upToNextMajor(from: "1.6.3")) ], targets: [ .target( name: "MyPackage", dependencies: ["Hero"]) ] ) ``` -------------------------------- ### Start Animation Source: https://github.com/herotransitions/hero/blob/develop/docs/docsets/Hero.docset/Contents/Resources/Documents/Classes/HeroTransition.html Initiates the animation sequence for the transition. ```APIDOC ## POST /herotransitions/hero/start ### Description Initiates the animation sequence for the transition. ### Method POST ### Endpoint /herotransitions/hero/start ### Parameters No parameters required. ### Request Example ```json {} ``` ### Response #### Success Response (200) - **message** (string) - Indicates that the animation has started. #### Response Example ```json { "message": "Animation started" } ``` ``` -------------------------------- ### Start Interactive Transition Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroTransition.html Starts an interactive view controller transition. It takes a transition context object to manage the interaction. ```swift @MainActor public func startInteractiveTransition(_ transitionContext: UIViewControllerContextTransitioning) ``` -------------------------------- ### Sample Gesture Handler for Interactive Transitions Source: https://github.com/herotransitions/hero/wiki/Interactive-Transition This Swift code snippet demonstrates a typical gesture recognizer handler for initiating and controlling an interactive Hero transition. It updates the transition progress, applies position modifiers to a cell's image view during movement, and decides whether to end or cancel the transition based on the final progress and velocity. ```swift func pan() { let translation = panGR.translation(in: nil) let progress = translation.y / 2 / collectionView!.bounds.height switch panGR.state { case .began: Hero.shared.setDefaultAnimationForNextTransition(.fade) hero_dismissViewController() case .changed: Hero.shared.update(progress: Double(progress)) if let cell = collectionView?.visibleCells[0] as? ScrollingImageCell { let currentPos = CGPoint(x: translation.x + view.center.x, y: translation.y + view.center.y) Hero.shared.apply(modifiers: [.position(currentPos)], to: cell.imageView) } default: if progress + panGR.velocity(in: nil).y / collectionView!.bounds.height > 0.3 { Hero.shared.end() } else { Hero.shared.cancel() } } } ``` -------------------------------- ### Start Interactive Transition Declaration (Swift) Source: https://github.com/herotransitions/hero/blob/develop/docs/docsets/Hero.docset/Contents/Resources/Documents/Classes/HeroTransition.html Declares the method to initiate an interactive transition. This is called when an interactive gesture begins and the transition needs to start. ```swift @MainActor public func startInteractiveTransition(_ transitionContext: UIViewControllerContextTransitioning) ``` -------------------------------- ### Start Transition with HeroTransitions Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroTransition.html Initiates the transition process. This method is called to begin the overall transition sequence, potentially orchestrating multiple animations and view changes. ```swift public func start() ``` -------------------------------- ### Get Target State by Key Source: https://github.com/herotransitions/hero/blob/develop/docs/docsets/Hero.docset/Contents/Resources/Documents/Structs/HeroTargetState.html Retrieves a custom item for a specific key from the target state. ```APIDOC ## GET /herotransitions/hero/targetstate/{key} ### Description Retrieves a custom item for a specific key from the target state. ### Method GET ### Endpoint /herotransitions/hero/targetstate/{key} ### Parameters #### Path Parameters - **key** (string) - Required - The key to retrieve the item for. ### Response #### Success Response (200) - **item** (any) - The custom item associated with the key. #### Response Example ```json { "item": "some_value" } ``` ``` -------------------------------- ### Hero Interactive Transition Methods Source: https://github.com/herotransitions/hero/wiki/Interactive-Transition These methods on `Hero.shared` are essential for managing interactive transitions. `update(progress:)` controls the transition's advancement, `end()` and `cancel()` finalize the transition by animating to the end or beginning state respectively, and `apply(modifiers:to:)` allows for dynamic overriding of view properties during the animation. ```swift /** Update the progress for the interactive transition. - Parameters: - progress: the current progress, must be between 0...1 */ public func update(progress: Double) /** Finish the interactive transition. Will stop the interactive transition and animate from the current state to the **end** state */ public func end(animate: Bool = true) /** Cancel the interactive transition. Will stop the interactive transition and animate from the current state to the **begining** state */ public func cancel(animate: Bool = true) /** Override modifiers during an interactive animation. For example: Hero.shared.apply([.position(x:50, y:50)], to:view) will set the view's position to 50, 50 - Parameters: - modifiers: the modifiers to override - view: the view to override to */ public func apply(modifiers: [HeroModifier], to view: UIView) ``` -------------------------------- ### Animate Transition with HeroTransitions Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroTransition.html Initiates the animation process for a transition. This method is fundamental for starting the visual transition between states or view controllers. No specific parameters are required as it operates on the current transition state. ```swift public func animate() ``` -------------------------------- ### Enable Hero and Set View Modifiers (Swift) Source: https://github.com/herotransitions/hero/blob/develop/docs/docsets/Hero.docset/Contents/Resources/Documents/index.html This example shows how to enable Hero for a view controller and apply modifiers to views. 'self.hero.isEnabled = true' activates Hero's transition capabilities. 'hero.modifiers' allow for custom animations like translation or cascading effects on groups of views. ```swift self.hero.isEnabled = true redView.hero.id = "ironMan" blackView.hero.id = "batMan" whiteView.hero.modifiers = [.translate(y:100)] ``` -------------------------------- ### Swift: Plugin API Changes for Duration and Progress Source: https://github.com/herotransitions/hero/wiki/Change-Log In version 0.0.3, the Hero plugin API was updated to provide more clarity regarding duration and progress handling. The `seekTo` method's parameter changed from `progress: Double` to `timePassed: TimeInterval`. Similarly, the `resume` method's `progress: Double` parameter was replaced with `timePassed: TimeInterval`. The library also started providing dynamic duration by default, aligning with Material Design guidelines. ```swift // Plugin API changes in version 0.0.3: // seekTo: // Old: func seekTo(progress: Double) // New: func seekTo(timePassed: TimeInterval) // resume: // Old: func resume(progress: Double, reverse: Bool) // New: func resume(timePassed: TimeInterval, reverse: Bool) ``` -------------------------------- ### Wants Interactive Start Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroTransition.html A boolean value indicating whether the transition should start interactively. This is a computed property. ```swift @MainActor public var wantsInteractiveStart: Bool { get } ``` -------------------------------- ### Swift: Control Hero Snapshot and Rendering Options Source: https://context7.com/herotransitions/hero/llms.txt Illustrates how to control Hero's snapshot generation and rendering behavior for animations using modifiers like .useOptimizedSnapshot, .useLayerRenderSnapshot, and .useNoSnapshot. Also shows how to force animations for offscreen views. Requires the Hero framework. ```swift class SnapshotOptionsViewController: UIViewController { let optimizedView = UIView() let layerRenderView = UIStackView() let noSnapshotView = UIView() override func viewDidLoad() { super.viewDidLoad() self.hero.isEnabled = true // Default optimized snapshot (fastest) optimizedView.hero.modifiers = [.useOptimizedSnapshot, .fade] view.addSubview(optimizedView) // Layer render snapshot (for complex views like UIStackView) layerRenderView.hero.modifiers = [.useLayerRenderSnapshot, .scale(0.5)] view.addSubview(layerRenderView) // No snapshot (animates real view - use with caution) noSnapshotView.hero.modifiers = [.useNoSnapshot, .translate(y: 100)] view.addSubview(noSnapshotView) // Force animation even if view is offscreen let forcedView = UIView() forcedView.hero.modifiers = [.forceAnimate] view.addSubview(forcedView) } } ``` -------------------------------- ### Change Target State for Interactive Animation with HeroTransitions Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroTransition.html Overrides the target state for an interactive animation. This method can alter the starting or ending state of the animation for a specific view. 'isDestination' determines if the change applies to the start or end state. ```swift public func changeTarget(modifiers: [HeroModifier], isDestination: Bool = true, to view: UIView) ``` -------------------------------- ### Apply Modifiers at Transition Start (Swift, Overload) Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroModifier.html An alternative static method to apply an array of HeroModifiers at the start of a transition. This method serves a similar purpose to 'beginWith(_:)' by setting initial states or replacing target states without animation. ```swift public static func beginWith(modifiers: [HeroModifier]) -> HeroModifier ``` -------------------------------- ### Swift: Navigate with Unwind and Replace View Controllers Source: https://context7.com/herotransitions/hero/llms.txt Shows how to use Hero's navigation utilities to unwind to specific view controllers (root, by instance, or by class), replace the current view controller with animation, and perform a smart dismiss/pop operation. Requires the Hero framework. ```swift class NavigationUtilitiesViewController: UIViewController { func unwindToRoot() { // Unwind to root view controller with Hero animation hero.unwindToRootViewController() } func unwindToSpecificController() { // Unwind to a specific view controller instance if let targetVC = navigationController?.viewControllers.first(where: { $0 is HomeViewController }) { hero.unwindToViewController(targetVC) } } func unwindByClass() { // Unwind to first view controller of a specific class hero.unwindToViewController(withClass: HomeViewController.self) } func replaceCurrentController() { let replacementVC = UIViewController() replacementVC.hero.isEnabled = true // Replace current view controller with animation hero.replaceViewController(with: replacementVC) { print("Replacement complete") } } func dismissOrPop() { // Smart dismiss - pops if in navigation controller, dismisses otherwise hero.dismissViewController { print("Dismissed or popped") } } } ``` -------------------------------- ### HeroModifier Size Source: https://github.com/herotransitions/hero/blob/develop/docs/docsets/Hero.docset/Contents/Resources/Documents/Classes/HeroModifier.html Sets the starting or ending size for the view during the transition. ```APIDOC ## HeroModifier size ### Description Set the size for the view to animate from/to. ### Method static func size(_ size: CGSize) -> HeroModifier ### Endpoint N/A (Modifier function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **size** (CGSize) - Required - The target size for the view. ### Request Example ```json { "modifier": "size", "value": {"width": 100, "height": 50} } ``` ### Response #### Success Response (200) - **modifier** (HeroModifier) - The size modifier #### Response Example ```json { "modifier": "size", "value": {"width": 100, "height": 50} } ``` ``` -------------------------------- ### HeroModifier Position Source: https://github.com/herotransitions/hero/blob/develop/docs/docsets/Hero.docset/Contents/Resources/Documents/Classes/HeroModifier.html Sets the starting or ending position for the view during the transition. ```APIDOC ## HeroModifier position ### Description Set the position for the view to animate from/to. ### Method static func position(_ position: CGPoint) -> HeroModifier ### Endpoint N/A (Modifier function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **position** (CGPoint) - Required - The target position for the view. ### Request Example ```json { "modifier": "position", "value": {"x": 100, "y": 200} } ``` ### Response #### Success Response (200) - **modifier** (HeroModifier) - The position modifier #### Response Example ```json { "modifier": "position", "value": {"x": 100, "y": 200} } ``` ``` -------------------------------- ### Lexer Initializer - Swift Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/Lexer.html Initializes a new Lexer instance with the provided input string. This is the constructor for the Lexer class. ```swift public init(input: String) ``` -------------------------------- ### Apply Modifiers to View Source: https://github.com/herotransitions/hero/blob/develop/docs/docsets/Hero.docset/Contents/Resources/Documents/Classes/HeroTransition.html Overrides modifiers for a specific view during an interactive animation. For example, to set a view's position. ```APIDOC ## POST /herotransitions/hero/applyModifiers ### Description Override modifiers during an interactive animation. For example, `Hero.shared.apply([.position(x:50, y:50)], to:view)` will set the view’s position to 50, 50. ### Method POST ### Endpoint /herotransitions/hero/applyModifiers ### Parameters #### Request Body - **modifiers** (Array) - Required - The list of modifiers to apply. - **view** (UIView) - Required - The view to which the modifiers will be applied. ### Request Example ```json { "modifiers": [ { "type": "position", "x": 50, "y": 50 } ], "view": "" } ``` ### Response #### Success Response (200) - **message** (string) - Indicates that the modifiers were successfully applied. #### Response Example ```json { "message": "Modifiers applied successfully" } ``` ``` -------------------------------- ### Setting Modal Animation Type in Swift Source: https://github.com/herotransitions/hero/blob/develop/docs/index.html Demonstrates how to specify different default animations for presenting and dismissing modal view controllers using the Hero library. This allows for customized transition behaviors. ```swift self.hero.modalAnimationType = .selectBy(presenting:.zoom, dismissing:.zoomOut) ``` -------------------------------- ### HeroViewControllerDelegate Protocol Source: https://github.com/herotransitions/hero/blob/develop/docs/docsets/Hero.docset/Contents/Resources/Documents/Protocols/HeroViewControllerDelegate.html The HeroViewControllerDelegate protocol provides optional methods to observe and influence the start, end, and cancellation of Hero animations from a view controller's perspective. ```APIDOC ## HeroViewControllerDelegate Protocol ### Description The `HeroViewControllerDelegate` protocol defines optional methods that can be implemented by a view controller to receive callbacks during the Hero animation lifecycle. This allows for custom logic to be executed when an animation starts, ends, or is cancelled. ### Methods #### `heroWillStartAnimatingFrom(viewController:)` ##### Description Called just before a Hero animation begins originating from the specified view controller. ##### Declaration ```swift @objc optional func heroWillStartAnimatingFrom(viewController: UIViewController) ``` #### `heroDidEndAnimatingFrom(viewController:)` ##### Description Called after a Hero animation has successfully completed originating from the specified view controller. ##### Declaration ```swift @objc optional func heroDidEndAnimatingFrom(viewController: UIViewController) ``` #### `heroDidCancelAnimatingFrom(viewController:)` ##### Description Called when a Hero animation originating from the specified view controller is cancelled. ##### Declaration ```swift @objc optional func heroDidCancelAnimatingFrom(viewController: UIViewController) ``` ``` -------------------------------- ### Swift: Begin Hero Modifier Animation Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroModifier.html Initializes a HeroModifier with a variable number of HeroModifier instances. This is used to start a sequence of animation modifiers. ```swift public static func beginWith(_ modifiers: HeroModifier...) -> HeroModifier ``` -------------------------------- ### HeroPlugin - init() Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroPlugin.html Initializes a new instance of HeroPlugin. This is an initializer and typically not called directly by the user. ```APIDOC ## HeroPlugin - init() ### Description Initializes a new instance of HeroPlugin. ### Method `init()` ### Endpoint N/A (Initializer) ### Parameters None ### Request Example N/A ### Response N/A ### Response Example N/A ``` -------------------------------- ### Swift: Animate Tab Bar Controller Tab Switches Source: https://context7.com/herotransitions/hero/llms.txt Demonstrates how to enable Hero animations for tab bar controller tab switches and set custom transition animations. It also shows how to implement shared elements between tabs for seamless transitions using Hero IDs. Requires the Hero framework. ```swift class TabBarSetupViewController: UITabBarController { override func viewDidLoad() { super.viewDidLoad() // Enable Hero for tab bar controller hero.isEnabled = true // Set transition animation for tab switches hero.tabBarAnimationType = .slide(direction: .left) // Other options: .fade, .zoom, .none, or any built-in animation type // Setup view controllers let firstVC = FirstViewController() let secondVC = SecondViewController() viewControllers = [firstVC, secondVC] } } class FirstViewController: UIViewController { let sharedElement = UIImageView() override func viewDidLoad() { super.viewDidLoad() // Shared element between tabs sharedElement.hero.id = "sharedTabImage" sharedElement.image = UIImage(named: "logo") view.addSubview(sharedElement) } } class SecondViewController: UIViewController { let sharedElement = UIImageView() override func viewDidLoad() { super.viewDidLoad() // Same hero ID creates smooth transition between tabs sharedElement.hero.id = "sharedTabImage" sharedElement.image = UIImage(named: "logo") view.addSubview(sharedElement) } } ``` -------------------------------- ### Implement Interactive Transition Control with Hero (Swift) Source: https://context7.com/herotransitions/hero/llms.txt Control transitions interactively using gestures with the Hero library. This involves enabling Hero on the view controller, adding a gesture recognizer, and updating the transition progress within the gesture handler. The transition can be finished or canceled based on gesture state and velocity. ```swift class InteractiveViewController: UIViewController { var panGesture: UIPanGestureRecognizer! override func viewDidLoad() { super.viewDidLoad() self.hero.isEnabled = true // Add pan gesture for interactive transition panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:))) view.addGestureRecognizer(panGesture) } @objc func handlePan(_ gesture: UIPanGestureRecognizer) { let translation = gesture.translation(in: view) let progress = translation.y / view.bounds.height switch gesture.state { case .began: // Start dismissing dismiss(animated: true, completion: nil) case .changed: // Update progress of interactive transition Hero.shared.update(progress) // Optionally apply modifiers during interaction let currentModifiers: [HeroModifier] = [.translate(y: translation.y)] Hero.shared.apply(modifiers: currentModifiers, to: view) case .ended: // Finish or cancel based on velocity and progress let velocity = gesture.velocity(in: view) if progress > 0.3 || velocity.y > 500 { Hero.shared.finish() } else { Hero.shared.cancel() } default: // Cancel on any other state Hero.shared.cancel() } } } ``` -------------------------------- ### Initialize Hero Transition (Swift) Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroTransition.html Initializes a new instance of the HeroTransition class. This is an undocumented initializer. ```swift public override init() ``` -------------------------------- ### HeroAnimator changeTarget Source: https://github.com/herotransitions/hero/blob/develop/docs/Protocols/HeroAnimator.html Changes the target state for a view, determining its appearance at the beginning or end of a transition. This method is crucial for defining the start and end points of animations. ```APIDOC ## POST /herotransitions/hero/changeTarget ### Description Changes the target state for a view, determining its appearance at the beginning or end of a transition. ### Method POST ### Endpoint `/herotransitions/hero/changeTarget` ### Parameters #### Request Body - **state** (HeroTargetState) - Required - The new target state. - **isDestination** (boolean) - Required - True if this is the destination state, false if it's the source state. - **view** (UIView) - Required - The view whose target state is being changed. ### Request Example ```json { "state": { "opacity": 0.0, "scale": 0.5 }, "isDestination": true, "view": "" } ``` ### Response #### Success Response (200) - **message** (string) - Indicates the target state was successfully changed. #### Response Example ```json { "message": "Target state changed successfully." } ``` ``` -------------------------------- ### Apply Hero Modifiers - Swift Source: https://github.com/herotransitions/hero/wiki/Coordinate-Space Applies translation modifiers to views using the Hero library. This example demonstrates how to set `heroModifiers` to achieve specific animation effects. ```swift greyView.heroModifiers = [.translate(y:100)] blackView.heroModifiers = nil redView.heroModifiers = [.translate(x:50)] ``` -------------------------------- ### UIViewController Extension - Hero Methods Source: https://github.com/herotransitions/hero/blob/develop/docs/Extensions/UIViewController.html This section details the Hero-related methods available for UIViewController instances. ```APIDOC ## UIViewController Extension Methods ### Description Provides access to Hero-specific methods for managing animations and hero functionality within View Controllers. ### Method N/A (Methods) ### Endpoint N/A (Extension Methods) ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ### Undocumented Methods * `ht_dismiss(_:)` * **Description**: Undocumented. * **Declaration**: `@IBAction @MainActor public func ht_dismiss(_ sender: UIView)` * **Parameters**: * `sender` (UIView) - The sender view. ``` -------------------------------- ### Configure Navigation Controller Transitions with Hero (Swift) Source: https://context7.com/herotransitions/hero/llms.txt Enable custom push/pop animations in navigation controllers using the Hero library. This is achieved by enabling Hero on the navigation controller and setting the `navigationAnimationType`. Smooth transitions between views with matching `hero.id` are automatically handled. ```swift class NavigationSetupViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Enable Hero on the navigation controller navigationController?.hero.isEnabled = true // Set default animation for push/pop navigationController?.hero.navigationAnimationType = .fade // Other options: .push(direction:), .pull(direction:), .slide(direction:), .zoom, etc. } func pushViewController() { let nextVC = DetailViewController() // Views with matching heroIDs will transition smoothly // The navigation animation type is already set on the navigation controller navigationController?.pushViewController(nextVC, animated: true) } } class DetailViewController: UIViewController { let imageView = UIImageView() override func viewDidLoad() { super.viewDidLoad() // Match this view with source view controller imageView.hero.id = "sharedImage" view.addSubview(imageView) } } ``` -------------------------------- ### Hide View for Animation - Swift Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroContext.html Hides a specified UIView, typically as part of the animation setup or teardown process. This helps manage the visibility of views during transitions. ```swift public func hide(view: UIView) ``` -------------------------------- ### UIViewController Hero Methods Source: https://github.com/herotransitions/hero/blob/develop/docs/docsets/Hero.docset/Contents/Resources/Documents/Extensions/UIViewController.html This section details the Hero-related methods available on the UIViewController extension. ```APIDOC ## UIViewController Extension Methods ### `ht_dismiss(_:)` **Description**: Undocumented action method to dismiss the view controller, likely triggered by a UI element. **Method**: ACTION **Endpoint**: N/A (Instance method) #### Parameters ##### Path Parameters None ##### Query Parameters None ##### Request Body None #### Declaration ```swift @IBAction @MainActor public func ht_dismiss(_ sender: UIView) ``` ``` -------------------------------- ### HeroModifier: Set Size (Swift) Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroModifier.html Sets the starting or ending size for the view's animation. It accepts a CGSize and returns a HeroModifier. This is useful for animating changes in view dimensions. ```swift public static func size(_ size: CGSize) -> HeroModifier ``` -------------------------------- ### Initialize HeroPlugin Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroPlugin.html Initializes a new instance of the HeroPlugin class. This is a standard initializer for Objective-C compatibility. ```swift public override required init() ``` -------------------------------- ### Clean Hero Context - Swift Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroContext.html Clears and resets the current Hero animation context. This function is used to ensure a clean state before starting new animations or when an animation sequence is completed. ```swift public func clean() ``` -------------------------------- ### Hero Target State Structure Source: https://github.com/herotransitions/hero/blob/develop/docs/Structs.html Documentation for the HeroTargetState structure, which is used to define target states for Hero transitions. It is currently undocumented but provides a link to more details and its GitHub source. ```APIDIDOC ## Structures ### HeroTargetState #### Description Undocumented structure used to define target states for Hero transitions. #### Declaration ```swift public struct HeroTargetState extension HeroTargetState: ExpressibleByArrayLiteral ``` #### See Also - [More details](Structs/HeroTargetState.html) - [Show on GitHub](https://github.com/HeroTransitions/Hero/tree/1.6.2//Sources/HeroTargetState.swift#L51-L126) ``` -------------------------------- ### HeroModifier: Set Position (Swift) Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroModifier.html Sets the starting or ending position for the view's animation. It takes a CGPoint as input and returns a HeroModifier. Useful for animating views to/from specific locations. ```swift public static func position(_ position: CGPoint) -> HeroModifier ``` -------------------------------- ### Enable Hero Transitions on a View Controller Source: https://context7.com/herotransitions/hero/llms.txt This code demonstrates how to enable Hero transitions for a specific view controller. It involves importing the Hero framework and setting the `isEnabled` property of the `hero` object to `true`. This is necessary before presenting or dismissing view controllers to activate Hero's animation capabilities. Dependencies: Hero framework. ```swift import Hero class DestinationViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Enable Hero for this view controller self.hero.isEnabled = true } } // Present the view controller let destinationVC = DestinationViewController() destinationVC.hero.isEnabled = true present(destinationVC, animated: true, completion: nil) ``` -------------------------------- ### Swift: Apply Advanced Animation Modifiers Source: https://context7.com/herotransitions/hero/llms.txt Demonstrates applying advanced Hero modifiers to views for custom animations, including translation, scaling, custom timing, spring effects, and conditional appearance/disappearance animations. Requires the Hero framework. ```swift class AdvancedModifiersViewController: UIViewController { let backgroundView = UIView() let contentView = UIView() let delayedView = UIView() override func viewDidLoad() { super.viewDidLoad() self.hero.isEnabled = true // Global coordinate space (required when views overlap during transition) backgroundView.hero.modifiers = [ .translate(y: 500), .useGlobalCoordinateSpace ] view.addSubview(backgroundView) // Custom timing and spring animation contentView.hero.modifiers = [ .scale(0.8), .duration(0.6), .timingFunction(.easeInOut), .spring(stiffness: 250, damping: 25) ] view.addSubview(contentView) // Conditional modifiers delayedView.hero.modifiers = [ .delay(0.3), .whenAppearing(.translate(x: -100), .fade), .whenDisappearing(.translate(x: 100), .fade) ] view.addSubview(delayedView) } } ``` -------------------------------- ### Hero Conditional Context Structure Source: https://github.com/herotransitions/hero/blob/develop/docs/Structs.html Documentation for the HeroConditionalContext structure, used for conditional logic within Hero transitions. This structure is also undocumented but linked for further information. ```APIDOC ## Structures ### HeroConditionalContext #### Description Undocumented structure used for conditional logic in Hero transitions. #### Declaration ```swift public struct HeroConditionalContext ``` #### See Also - [More details](Structs/HeroConditionalContext.html) - [Show on GitHub](https://github.com/HeroTransitions/Hero/tree/1.6.2//Sources/Preprocessors/ConditionalPreprocessor.swift#L27-L75) ``` -------------------------------- ### Hero Transition Property - Swift Source: https://github.com/herotransitions/hero/blob/develop/docs/docsets/Hero.docset/Contents/Resources/Documents/Protocols/HeroPreprocessor.html The 'hero' property within the HeroPreprocessor protocol. This property holds an instance of HeroTransition, likely used to manage the state and operations of a Hero transition. It is declared as a variable that can be get and set. ```swift var hero: HeroTransition! { get set } ``` -------------------------------- ### Controlling Interactive Transitions with Hero Source: https://github.com/herotransitions/hero/blob/develop/docs/docsets/Hero.docset/Contents/Resources/Documents/Classes/Hero.html This snippet demonstrates the core methods of the Hero singleton class for managing interactive transitions. It allows updating the transition progress, ending, canceling, and applying modifiers to views. ```swift func update(progress:Double) func end() func cancel() func apply(modifiers:[HeroModifier], to view:UIView) ``` -------------------------------- ### Hero Singleton API Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes.html Provides access to the singleton instance of the Hero class for controlling interactive transitions. ```APIDOC ## Hero Singleton API ### Description Provides access to the singleton instance of the Hero class for controlling interactive transitions. ### Method Access (Singleton) ### Endpoint N/A ### Parameters None ### Request Example ```swift Hero.shared ``` ### Response #### Success Response (200) An instance of the `Hero` class. #### Response Example ```swift Hero.shared ``` ## Methods for Controlling Interactive Transitions ### Description These methods are used to control the progress and state of interactive transitions managed by the `Hero` singleton. ### Method POST (Conceptual - these are method calls on the singleton) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift Hero.shared.update(progress: 0.5) Hero.shared.end() Hero.shared.cancel() Hero.shared.apply(modifiers: [HeroModifier.rotate(by: 90)], to: someView) ``` ### Response #### Success Response (200) Indicates successful execution of the transition control method. #### Response Example No explicit response body for these control methods. ``` -------------------------------- ### Get Paired View for View - Swift Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroContext.html Finds a UIView that shares the same heroID but is present in a different view controller. Returns nil if no paired view is found. This is crucial for hero transitions between different screens. ```swift public func pairedView(for view: UIView) -> UIView? ``` -------------------------------- ### ExprNode Initializer Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/ExprNode.html This snippet presents the initializer for the ExprNode class. It takes a single String argument named 'name' to create an instance of ExprNode. This initializer is crucial for instantiating the node with a specific name. ```Swift public init(name: String) ``` -------------------------------- ### Apply Modifiers at Transition Start (Swift) Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroModifier.html Applies an array of HeroModifiers directly to a view at the beginning of a transition. These modifiers are not animated and determine the initial state for source views or replace the target state for destination views. ```swift public static func beginWith(_ modifiers: [HeroModifier]) -> HeroModifier ``` -------------------------------- ### Hero Transition Control API Source: https://github.com/herotransitions/hero/blob/develop/docs/docsets/Hero.docset/Contents/Resources/Documents/Classes/Hero.html This section details the methods provided by the Hero singleton class for managing interactive transitions. These methods allow for updating transition progress, ending, canceling, and applying modifiers to views during a transition. ```APIDOC ## Hero Singleton Class ### Description The singleton class/object for controlling interactive transitions. ### Usage ```swift Hero.shared ``` ### Methods #### `update(progress: Double)` **Description:** Updates the progress of the current interactive transition. **Method:** `func update(progress: Double)` **Parameters:** - **progress** (Double) - The current progress of the transition, typically between 0.0 and 1.0. #### `end()` **Description:** Ends the current interactive transition successfully. **Method:** `func end()` #### `cancel()` **Description:** Cancels the current interactive transition. **Method:** `func cancel()` #### `apply(modifiers: [HeroModifier], to view: UIView)` **Description:** Applies a list of Hero modifiers to a specific view. **Method:** `func apply(modifiers: [HeroModifier], to view: UIView)` **Parameters:** - **modifiers** ([HeroModifier]) - An array of HeroModifier objects to apply. - **view** (UIView) - The target UIView to which the modifiers will be applied. ### Shared Singleton Instance #### `shared` **Description:** The shared singleton object for controlling the transition. **Declaration:** ```swift public static var shared: HeroTransition ``` **Endpoint:** `Hero.shared` ``` -------------------------------- ### Lexer Class Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/Lexer.html Documentation for the Lexer class, which is responsible for tokenizing input strings. It includes details on its initializer and the tokenize method. ```APIDOC ## Lexer Class Reference ### Description Undocumented class related to parsing. ### Initializer #### `init(input:)` - **Description**: Initializes the Lexer with a given input string. - **Method**: `init` - **Endpoint**: N/A (Initializer) - **Parameters**: - **`input`** (String) - Required - The input string to be tokenized. ``` ```APIDOC ### Method #### `tokenize()` - **Description**: Tokenizes the input string provided during initialization. - **Method**: `func` - **Endpoint**: N/A (Method) - **Returns**: An array of `Token` enums representing the tokenized input. ``` -------------------------------- ### Apply Hero State to View in Swift Source: https://github.com/herotransitions/hero/blob/develop/docs/Protocols/HeroAnimator.html Applies a specific HeroTargetState to a given UIView. This is a core function for setting up the start or end state of a hero transition, defining properties like position, opacity, and scale. ```swift func apply(state: HeroTargetState, to view: UIView) ``` -------------------------------- ### UIViewController Extensions Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroExtension.html Extensions for `UIViewController` to manage view controller dismissals, unwinding, and replacements. ```APIDOC ## UIViewController Extensions ### Description Provides methods for dismissing view controllers with animations, unwinding to specific view controllers, and replacing the current view controller. ### Method N/A (Methods) ### Endpoint N/A (Extension) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## POST /herotransitions/hero/dismissViewController ### Description Dismisses the current view controller with an animation. If the view controller is within a `UINavigationController`, it performs a `popViewController`. ### Method POST ### Endpoint `UIViewController.dismissViewController(completion:)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **completion** (() -> Void)? - Optional completion handler to be executed after dismissal. ### Request Example ```swift self.dismissViewController { print("View controller dismissed") } ``` ### Response #### Success Response (200) Void #### Response Example N/A ## POST /herotransitions/hero/unwindToRootViewController ### Description Unwinds to the root view controller using Hero animations. ### Method POST ### Endpoint `UIViewController.unwindToRootViewController()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift self.unwindToRootViewController() ``` ### Response #### Success Response (200) Void #### Response Example N/A ## POST /herotransitions/hero/unwindToViewController ### Description Unwinds to a specific target view controller using Hero animations. ### Method POST ### Endpoint `UIViewController.unwindToViewController(_:)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **toViewController** (UIViewController) - The target view controller to unwind to. ### Request Example ```swift if let targetVC = self.navigationController?.viewControllers.first { self.unwindToViewController(targetVC) } ``` ### Response #### Success Response (200) Void #### Response Example N/A ## POST /herotransitions/hero/unwindToViewControllerWithSelector ### Description Unwinds to a view controller identified by a specific selector using Hero animations. This method is undocumented. ### Method POST ### Endpoint `UIViewController.unwindToViewController(withSelector:)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **withSelector** (Selector) - The selector identifying the target view controller. ### Request Example ```swift let selector = #selector(MyViewController.someMethod) self.unwindToViewController(withSelector: selector) ``` ### Response #### Success Response (200) Void #### Response Example N/A ## POST /herotransitions/hero/unwindToViewControllerWithClass ### Description Unwinds to a view controller of a given class using Hero animations. ### Method POST ### Endpoint `UIViewController.unwindToViewController(withClass:)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **withClass** (AnyClass) - The class of the target view controller. ### Request Example ```swift self.unwindToViewController(withClass: MyViewController.self) ``` ### Response #### Success Response (200) Void #### Response Example N/A ## POST /herotransitions/hero/unwindToViewControllerWithMatchBlock ### Description Unwinds to the first view controller for which the provided match block returns `true`, using Hero animations. ### Method POST ### Endpoint `UIViewController.unwindToViewController(withMatchBlock:)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **withMatchBlock** ((UIViewController) -> Bool) - A closure that takes a `UIViewController` and returns `true` if it's the target view controller. ### Request Example ```swift self.unwindToViewController { vc in return vc is MyViewController && (vc as! MyViewController).someProperty == "target" } ``` ### Response #### Success Response (200) Void #### Response Example N/A ## POST /herotransitions/hero/replaceViewController ### Description Replaces the current view controller with a new one on the navigation, modal, or root view controller stack of a `UIWindow`, with an optional completion handler. ### Method POST ### Endpoint `UIViewController.replaceViewController(with:completion:)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **next** (UIViewController) - The new view controller to replace the current one with. - **completion** (() -> Void)? - Optional completion handler to be executed after replacement. ### Request Example ```swift let newVC = UIViewController() self.replaceViewController(with: newVC) { print("ViewController replaced") } ``` ### Response #### Success Response (200) Void #### Response Example N/A ``` -------------------------------- ### Get Hero Transition Progress (Swift) Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroTransition.html The `progress` property returns a Double value representing the current state of an ongoing transition. A value of 0 indicates no transition is active. This is a public, internally settable property. ```swift public internal(set) var progress: Double { get set } ``` -------------------------------- ### Set Hero Target State for View - Swift Source: https://github.com/herotransitions/hero/blob/develop/docs/Classes/HeroContext.html Provides subscript access to set or get the HeroTargetState for a given UIView. This allows direct manipulation of a view's animation state within the Hero context. ```swift public subscript(view: UIView) -> HeroTargetState? { get set } ``` -------------------------------- ### HeroViewControllerDelegate Protocol Methods (Swift) Source: https://github.com/herotransitions/hero/blob/develop/docs/Protocols/HeroViewControllerDelegate.html This protocol defines optional methods that can be implemented to observe the lifecycle of Hero view controller transitions. These methods are called on the delegate object when specific transition events occur, such as starting, ending, or canceling an animation. ```swift protocol HeroViewControllerDelegate { @objc optional func heroWillStartAnimatingFrom(viewController: UIViewController) @objc optional func heroDidEndAnimatingFrom(viewController: UIViewController) @objc optional func heroDidCancelAnimatingFrom(viewController: UIViewController) } ```