//
//  ActionSheetAnimator.swift
//  PaiAi
//
//  Created by FFIB on 2018/12/17.
//  Copyright © 2018 FFIB. All rights reserved.
//

import UIKit

public struct ActionSheetAnimator: PresentAnimatable {
    public func contentViewAppearAnimation(duration: TimeInterval, in view: UIView) {
        let animation = CATransition()
        
        animation.duration = duration
        animation.type = .moveIn
        animation.subtype = .fromTop
        
        view.layer.add(animation, forKey: nil)
    }
    
    public func contentViewDisappearAnimation(duration: TimeInterval, in view: UIView) {
        let fromValue = view.layer.position.y
        let toValue = fromValue + view.bounds.height
        
        let animation = CABasicAnimation(keyPath: "position.y")
        
        animation.toValue = toValue
        animation.duration = duration
        animation.fromValue = fromValue
        animation.isRemovedOnCompletion = false
        animation.fillMode = .forwards
        
        view.layer.add(animation, forKey: nil)
    }
}