自定义Push动画 --- Swift 4

//MARK: Push动画

///从下向上推出(push出页面 ----> 从底部到顶部 垂直出现-消失)
func setPushAnimatedWithTransition(customSelf: UINavigationController) {
    
    if #available(iOS 9.0, *) {
        
    }
    
    let animation = CATransition.init()
    
    animation.duration = 0.3
    
    animation.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionLinear)
    
    animation.type = kCATransitionPush
    
    animation.subtype = kCATransitionFromTop//kCATransitionFromTop控制类型
    
    customSelf.view.layer.add(animation, forKey: nil)
}

///从上向下推出(push出页面 ---> 从顶部到底部 垂直出现-消失)
func setPopAnimatedWithTransition(customSelf: UINavigationController) {
    
    if #available(iOS 9.0, *) {
        
    }
    
    let animation = CATransition.init()
    
    animation.duration = 0.3
    
    animation.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionLinear)
    
    animation.type = kCATransitionReveal//kCATransitionPush
    
    animation.subtype = kCATransitionFromBottom
    
    customSelf.view.layer.add(animation, forKey: nil)
}


//使用示例--->那个页面去push想要此效果,push前调用此方法
//setPushAnimatedWithTransition(customSelf: self.navigationController!)
//self.navigationController?.pushViewController(SelectLogController(), animated: false)//此处animated必须false

 

你可能感兴趣的:(push动画)