Back to Hero

HeroModifier

docs/Classes/HeroModifier.html

1.6.423.5 KB
Original Source

HeroModifier

public final class HeroModifier
extension HeroModifier: HeroStringConvertible

Undocumented

Show on GitHub

`

                init(applyFunction:)
                `

Undocumented

Declaration

Swift

public init(applyFunction: @escaping (inout HeroTargetState) -> Void)

Show on GitHub

`

                beginWith(_:)
                `

Apply modifiers directly to the view at the start of the transition. The modifiers supplied here won’t be animated. For source views, modifiers are set directly at the beginning of the animation. For destination views, they replace the target state (final appearance).

Declaration

Swift

public static func beginWith(_ modifiers: [HeroModifier]) -> HeroModifier

Show on GitHub

`

                beginWith(modifiers:)
                `

Undocumented

Declaration

Swift

public static func beginWith(modifiers: [HeroModifier]) -> HeroModifier

Show on GitHub

`

                beginWith(_:)
                `

Undocumented

Declaration

Swift

public static func beginWith(_ modifiers: HeroModifier...) -> HeroModifier

Show on GitHub

`

                useGlobalCoordinateSpace
                `

Use global coordinate space.

When using global coordinate space. The view become a independent view that is not a subview of any view. It won’t move when its parent view moves, and won’t be affected by parent view’s attributes.

When a view is matched, this is automatically enabled. The source modifier will also enable this.

Global coordinate space is default for all views prior to version 0.1.3

Declaration

Swift

public static var useGlobalCoordinateSpace: HeroModifier

Show on GitHub

`

                ignoreSubviewModifiers
                `

ignore all heroModifiers attributes for a view’s direct subviews.

Declaration

Swift

public static var ignoreSubviewModifiers: HeroModifier

Show on GitHub

`

                ignoreSubviewModifiers(recursive:)
                `

ignore all heroModifiers attributes for a view’s subviews.

  • recursive: if false, will only ignore direct subviews’ modifiers. default false.

Declaration

Swift

public static func ignoreSubviewModifiers(recursive: Bool = false) -> HeroModifier

Show on GitHub

`

                useOptimizedSnapshot
                `

Will create snapshot optimized for different view type. For custom views or views with masking, useOptimizedSnapshot might create snapshots that appear differently than the actual view. In that case, use .useNormalSnapshot or .useSlowRenderSnapshot to disable the optimization.

This modifier actually does nothing by itself since .useOptimizedSnapshot is the default.

Declaration

Swift

public static var useOptimizedSnapshot: HeroModifier

Show on GitHub

`

                useNormalSnapshot
                `

Create snapshot using snapshotView(afterScreenUpdates:).

Declaration

Swift

public static var useNormalSnapshot: HeroModifier

Show on GitHub

`

                useLayerRenderSnapshot
                `

Create snapshot using layer.render(in: currentContext). This is slower than .useNormalSnapshot but gives more accurate snapshot for some views (eg. UIStackView).

Declaration

Swift

public static var useLayerRenderSnapshot: HeroModifier

Show on GitHub

`

                useNoSnapshot
                `

Force Hero to not create any snapshot when animating this view. This will mess up the view hierarchy, therefore, view controllers have to rebuild its view structure after the transition finishes.

Declaration

Swift

public static var useNoSnapshot: HeroModifier

Show on GitHub

`

                forceAnimate
                `

Force the view to animate.

By default, Hero will not animate if the view is outside the screen bounds or if there is no animatable hero modifier, unless this modifier is used.

Declaration

Swift

public static var forceAnimate: HeroModifier

Show on GitHub

`

                useScaleBasedSizeChange
                `

Force Hero use scale based size animation. This will convert all .size modifier into .scale modifier. This is to help Hero animate layers that doesn’t support bounds animation. Also gives better performance.

Declaration

Swift

public static var useScaleBasedSizeChange: HeroModifier

Show on GitHub

`

                from(node:)
                `

Undocumented

Declaration

Swift

public static func from(node: ExprNode) -> HeroModifier?

Show on GitHub

`

                fade
                `

Fade the view during transition

Declaration

Swift

public static var fade: HeroModifier

Show on GitHub

`

                forceNonFade
                `

Force don’t fade view during transition

Declaration

Swift

public static var forceNonFade: HeroModifier

Show on GitHub

`

                position(_:)
                `

Set the position for the view to animate from/to.

  • position: position for the view to animate from/to

Declaration

Swift

public static func position(_ position: CGPoint) -> HeroModifier

Show on GitHub

`

                size(_:)
                `

Set the size for the view to animate from/to.

  • size: size for the view to animate from/to

Declaration

Swift

public static func size(_ size: CGSize) -> HeroModifier

Show on GitHub

`

                transform(_:)
                `

Set the transform for the view to animate from/to. Will override previous perspective, scale, translate, & rotate modifiers

  • t: the CATransform3D object

Declaration

Swift

public static func transform(_ t: CATransform3D) -> HeroModifier

Show on GitHub

`

                perspective(_:)
                `

Set the perspective on the transform. use in combination with the rotate modifier.

  • perspective: set the camera distance of the transform

Declaration

Swift

public static func perspective(_ perspective: CGFloat) -> HeroModifier

Show on GitHub

`

                scale(x:y:z:)
                `

Scale 3d

  • x: scale factor on x axis, default 1
  • y: scale factor on y axis, default 1
  • z: scale factor on z axis, default 1

Declaration

Swift

public static func scale(x: CGFloat = 1, y: CGFloat = 1, z: CGFloat = 1) -> HeroModifier

Show on GitHub

`

                scale(_:)
                `

Scale in x & y axis

  • xy: scale factor in both x & y axis

Declaration

Swift

public static func scale(_ xy: CGFloat) -> HeroModifier

Show on GitHub

`

                translate(x:y:z:)
                `

Translate 3d

  • x: translation distance on x axis in display pixel, default 0
  • y: translation distance on y axis in display pixel, default 0
  • z: translation distance on z axis in display pixel, default 0

Declaration

Swift

public static func translate(x: CGFloat = 0, y: CGFloat = 0, z: CGFloat = 0) -> HeroModifier

Show on GitHub

`

                translate(_:z:)
                `

Undocumented

Declaration

Swift

public static func translate(_ point: CGPoint, z: CGFloat = 0) -> HeroModifier

Show on GitHub

`

                rotate(x:y:z:)
                `

Rotate 3d

  • x: rotation on x axis in radian, default 0
  • y: rotation on y axis in radian, default 0
  • z: rotation on z axis in radian, default 0

Declaration

Swift

public static func rotate(x: CGFloat = 0, y: CGFloat = 0, z: CGFloat = 0) -> HeroModifier

Show on GitHub

`

                rotate(_:z:)
                `

Undocumented

Declaration

Swift

public static func rotate(_ point: CGPoint, z: CGFloat = 0) -> HeroModifier

Show on GitHub

`

                rotate(_:)
                `

Rotate 2d

  • z: rotation in radian

Declaration

Swift

public static func rotate(_ z: CGFloat) -> HeroModifier

Show on GitHub

UIKit

`

                backgroundColor(_:)
                `

Set the backgroundColor for the view to animate from/to.

  • backgroundColor: backgroundColor for the view to animate from/to

Declaration

Swift

public static func backgroundColor(_ backgroundColor: UIColor) -> HeroModifier

Show on GitHub

`

                borderColor(_:)
                `

Set the borderColor for the view to animate from/to.

  • borderColor: borderColor for the view to animate from/to

Declaration

Swift

public static func borderColor(_ borderColor: UIColor) -> HeroModifier

Show on GitHub

`

                shadowColor(_:)
                `

Set the shadowColor for the view to animate from/to.

  • shadowColor: shadowColor for the view to animate from/to

Declaration

Swift

public static func shadowColor(_ shadowColor: UIColor) -> HeroModifier

Show on GitHub

`

                overlay(color:opacity:)
                `

Create an overlay on the animating view.

  • color: color of the overlay
  • opacity: opacity of the overlay

Declaration

Swift

public static func overlay(color: UIColor, opacity: CGFloat) -> HeroModifier

Show on GitHub

`

                opacity(_:)
                `

Set the opacity for the view to animate from/to.

  • opacity: opacity for the view to animate from/to

Declaration

Swift

public static func opacity(_ opacity: CGFloat) -> HeroModifier

Show on GitHub

`

                cornerRadius(_:)
                `

Set the cornerRadius for the view to animate from/to.

  • cornerRadius: cornerRadius for the view to animate from/to

Declaration

Swift

public static func cornerRadius(_ cornerRadius: CGFloat) -> HeroModifier

Show on GitHub

`

                zPosition(_:)
                `

Set the zPosition for the view to animate from/to.

  • zPosition: zPosition for the view to animate from/to

Declaration

Swift

public static func zPosition(_ zPosition: CGFloat) -> HeroModifier

Show on GitHub

`

                contentsRect(_:)
                `

Set the contentsRect for the view to animate from/to.

  • contentsRect: contentsRect for the view to animate from/to

Declaration

Swift

public static func contentsRect(_ contentsRect: CGRect) -> HeroModifier

Show on GitHub

`

                contentsScale(_:)
                `

Set the contentsScale for the view to animate from/to.

  • contentsScale: contentsScale for the view to animate from/to

Declaration

Swift

public static func contentsScale(_ contentsScale: CGFloat) -> HeroModifier

Show on GitHub

`

                borderWidth(_:)
                `

Set the borderWidth for the view to animate from/to.

  • borderWidth: borderWidth for the view to animate from/to

Declaration

Swift

public static func borderWidth(_ borderWidth: CGFloat) -> HeroModifier

Show on GitHub

`

                shadowOpacity(_:)
                `

Set the shadowOpacity for the view to animate from/to.

  • shadowOpacity: shadowOpacity for the view to animate from/to

Declaration

Swift

public static func shadowOpacity(_ shadowOpacity: CGFloat) -> HeroModifier

Show on GitHub

`

                shadowOffset(_:)
                `

Set the shadowOffset for the view to animate from/to.

  • shadowOffset: shadowOffset for the view to animate from/to

Declaration

Swift

public static func shadowOffset(_ shadowOffset: CGSize) -> HeroModifier

Show on GitHub

`

                shadowRadius(_:)
                `

Set the shadowRadius for the view to animate from/to.

  • shadowRadius: shadowRadius for the view to animate from/to

Declaration

Swift

public static func shadowRadius(_ shadowRadius: CGFloat) -> HeroModifier

Show on GitHub

`

                shadowPath(_:)
                `

Set the shadowPath for the view to animate from/to.

  • shadowPath: shadowPath for the view to animate from/to

Declaration

Swift

public static func shadowPath(_ shadowPath: CGPath) -> HeroModifier

Show on GitHub

`

                masksToBounds(_:)
                `

Set the masksToBounds for the view to animate from/to.

  • masksToBounds: masksToBounds for the view to animate from/to

Declaration

Swift

public static func masksToBounds(_ masksToBounds: Bool) -> HeroModifier

Show on GitHub

`

                duration(_:)
                `

Sets the duration of the animation for a given view. If not used, Hero will use determine the duration based on the distance and size changes.

  • duration: duration of the animation

Note: a duration of .infinity means matching the duration of the longest animation. same as .durationMatchLongest

Declaration

Swift

public static func duration(_ duration: TimeInterval) -> HeroModifier

Show on GitHub

`

                durationMatchLongest
                `

Sets the duration of the animation for a given view to match the longest animation of the transition.

Declaration

Swift

public static var durationMatchLongest: HeroModifier

Show on GitHub

`

                delay(_:)
                `

Sets the delay of the animation for a given view.

  • delay: delay of the animation

Declaration

Swift

public static func delay(_ delay: TimeInterval) -> HeroModifier

Show on GitHub

`

                timingFunction(_:)
                `

Sets the timing function of the animation for a given view. If not used, Hero will use determine the timing function based on whether or not the view is entering or exiting the screen.

  • timingFunction: timing function of the animation

Declaration

Swift

public static func timingFunction(_ timingFunction: CAMediaTimingFunction) -> HeroModifier

Show on GitHub

`

                spring(stiffness:damping:)
                `

(iOS 9+) Use spring animation with custom stiffness & damping. The duration will be automatically calculated. Will be ignored if arc, timingFunction, or duration is set.

  • stiffness: stiffness of the spring
  • damping: damping of the spring

Declaration

Swift

@available(iOS 9, *)
public static func spring(stiffness: CGFloat, damping: CGFloat) -> HeroModifier

Show on GitHub

`

                source(heroID:)
                `

Transition from/to the state of the view with matching heroID Will also force the view to use global coordinate space.

The following layer properties will be animated from the given view.

position bounds.size cornerRadius transform shadowColor shadowOpacity shadowOffset shadowRadius shadowPath

Note that the following properties won’t be taken from the source view.

backgroundColor borderWidth borderColor

  • heroID: the source view’s heroId.

Declaration

Swift

public static func source(heroID: String) -> HeroModifier

Show on GitHub

`

                arc
                `

Works in combination with position modifier to apply a natural curve when moving to the destination.

Declaration

Swift

public static var arc: HeroModifier

Show on GitHub

`

                arc(intensity:)
                `

Works in combination with position modifier to apply a natural curve when moving to the destination.

  • intensity: a value of 1 represent a downward natural curve ╰. a value of -1 represent a upward curve ╮. default is 1.

Declaration

Swift

public static func arc(intensity: CGFloat = 1) -> HeroModifier

Show on GitHub

`

                cascade
                `

Cascade applys increasing delay modifiers to subviews

Declaration

Swift

public static var cascade: HeroModifier

Show on GitHub

`

                cascade(delta:direction:delayMatchedViews:)
                `

Cascade applys increasing delay modifiers to subviews

  • delta: delay in between each animation
  • direction: cascade direction
  • delayMatchedViews: whether or not to delay matched subviews until all cascading animation have started

Declaration

Swift

public static func cascade(delta: TimeInterval = 0.02,
                           direction: CascadeDirection = .topToBottom,
                           delayMatchedViews: Bool = false) -> HeroModifier

Show on GitHub

`

                when(_:_:)
                `

Apply modifiers only if the condition return true.

Declaration

Swift

public static func when(_ condition: @escaping (HeroConditionalContext) -> Bool, _ modifiers: [HeroModifier]) -> HeroModifier

Show on GitHub

`

                when(_:_:)
                `

Undocumented

Declaration

Swift

public static func when(_ condition: @escaping (HeroConditionalContext) -> Bool, _ modifiers: HeroModifier...) -> HeroModifier

Show on GitHub

`

                whenMatched(_:)
                `

Undocumented

Declaration

Swift

public static func whenMatched(_ modifiers: HeroModifier...) -> HeroModifier

Show on GitHub

`

                whenPresenting(_:)
                `

Undocumented

Declaration

Swift

public static func whenPresenting(_ modifiers: HeroModifier...) -> HeroModifier

Show on GitHub

`

                whenDismissing(_:)
                `

Undocumented

Declaration

Swift

public static func whenDismissing(_ modifiers: HeroModifier...) -> HeroModifier

Show on GitHub

`

                whenAppearing(_:)
                `

Undocumented

Declaration

Swift

public static func whenAppearing(_ modifiers: HeroModifier...) -> HeroModifier

Show on GitHub

`

                whenDisappearing(_:)
                `

Undocumented

Declaration

Swift

public static func whenDisappearing(_ modifiers: HeroModifier...) -> HeroModifier

Show on GitHub