嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 4 元微信扫码支付:4 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
Present方式弹出设置
public class Presentation: UIPresentationController {
lazy fileprivate var blackView: UIView = {
let view = UIView()
if let frame = self.containerView?.bounds {
view.frame = frame
}
return view
}()
override public func presentationTransitionWillBegin() {
presentedView?.frame = UIScreen.main.bounds
containerView?.addSubview(blackView)
containerView?.addSubview(presentedView ?? UIView())
presentingViewController.transitionCoordinator?.animateAlongsideTransition(in: blackView, animation: { (context) in
self.blackView.backgroundColor = colorLiteral(red: 0, green: 0, blue: 0, alpha: 1).withAlphaComponent(0.5)
}, completion: { (context) in
})
}
override public func dismissalTransitionWillBegin() {
presentingViewController.transitionCoordinator?.animateAlongsideTransition(in: blackView, animation: { (context) in
self.blackView.alpha = 0
}, completion: { (context) in
})
}
override public func dismissalTransitionDidEnd(_ completed: Bool) {
if completed {
presentedView?.removeFromSuperview()
blackView.removeFromSuperview()
}
}
}
//动画的类
class AnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning {
var present: Bool = true
var direction: Direction = .Up
var dismissDirection: Direction = .Up
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.65
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
if present {
showDirecton(dir: direction, transitionContext: transitionContext)
}else{
showDirecton(dir: dismissDirection, transitionContext: transitionContext)
}
}
fileprivate func showDirecton(dir: Direction, transitionContext: UIViewControllerContextTransitioning){
if present {
//创建控制器
let toView = transitionContext.view(forKey: UITransitionContextViewKey.to)
switch dir {
case.down:
//从上向下
toView?.frame.origin.y = -(toView?.frame.height ?? UIScreen.main.bounds.height)
break
case .Up:
//从下向上
toView?.frame.origin.y = toView?.frame.height ?? UIScreen.main.bounds.height
break
case .left:
//从左向右
toView?.frame.origin.x = -(toView?.frame.width ?? UIScreen.main.bounds.width)
break
case .right:
//从右向左
toView?.frame.origin.x = toView?.frame.width ?? UIScreen.main.bounds.width
break
}
UIView.animate(withDuration: 0.45, delay: 0.0, usingSpringWithDamping: 0.90, initialSpringVelocity: 1.0 / 0.5, options: .curveEaseInOut, animations: {
switch dir{
case .Up, .down:
toView?.frame.origin.y = 0
break
case .left, .right:
toView?.frame.origin.x = 0
break
}
}) { (finished) in
transitionContext.completeTransition(true)
}
}else{
let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from)
//销毁控制器
UIView.animate(withDuration: 0.45, delay: 0.0, usingSpringWithDamping: 0.90, initialSpringVelocity: 1.0 / 0.5, options: .curveEaseInOut, animations: {
switch dir{
case .Up:
fromView?.frame.origin.y = fromView?.frame.height ?? UIScreen.main.bounds.height
break
case .down:
fromView?.frame.origin.y = -(fromView?.frame.height ?? UIScreen.main.bounds.height)
break
case .left:
fromView?.frame.origin.x = -(fromView?.frame.width ?? UIScreen.main.bounds.width)
break
case .right:
fromView?.frame.origin.x = fromView?.frame.width ?? UIScreen.main.bounds.width
break
}
}) { (finished) in
transitionContext.completeTransition(true)
}
// UIView.animate(withDuration: 0.45, delay: 0.0, options: [.curveEaseInOut], animations: {
//
//
// }) { (finished) in
// transitionContext.completeTransition(true)
// }
}
}
}