Skip to content

Custom animation transitions on row hide/show #4

@malcommac

Description

@malcommac

ScrollStackRow allow row's controller view to perform custom animation when hide or show row.

Implementation is based upon the ScrollStackRowAnimatable. Your view controller should implement the method of this protocol in order to intercept hide/show events and perform custom animations.

public protocol ScrollStackRowAnimatable {
    
    /// Animation main info.
    var animationInfo: ScrollStackAnimationInfo { get }
    
    /// Animation will start to hide or show the row.
    /// - Parameter toHide: hide or show transition.
    func willBeginAnimationTransition(toHide: Bool)
    
    /// Animation to hide/show the row did end.
    /// - Parameter toHide: hide or show transition.
    func didEndAnimationTransition(toHide: Bool)
    
    /// Animation transition.
    /// - Parameter toHide: hide or show transition.
    func animateTransition(toHide: Bool)
    
}

The following example show how it works custom animation inside the demo app:

extension WelcomeVC: ScrollStackRowAnimatable {
    
    public var animationInfo: ScrollStackAnimationInfo {
        return ScrollStackAnimationInfo(duration: 1, delay: 0, springDamping: 0.8)
    }

    public func animateTransition(toHide: Bool) {
        switch toHide {
            case true:
                self.view.transform = CGAffineTransform(translationX: -100, y: 0)
                self.view.alpha = 0
            
            case false:
                self.view.transform = .identity
                self.view.alpha = 1
        }
    }
    
    public func willBeginAnimationTransition(toHide: Bool) {
        if toHide == false {
            self.view.transform = CGAffineTransform(translationX: -100, y: 0)
            self.view.alpha = 0
        }
    }
    
}

The result is this:

Dec-23-2019 18-44-38

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions