Slidoo
示例
要运行示例项目,请首先克隆仓库,然后在 Example 目录中运行 pod install
要求
- Xcode 10.0+
- iOS 9.0+
- Swift 4.2+
设置
GIF
从左到右 | 从右到左 |
---|---|
截图
从左到右
纵向 | 横向 |
---|---|
从右到左
纵向 | 横向 |
---|---|
Transition Delegate
添加 此类提供自定义展示控制器和动画控制器,用于展示和移除视图控制器
import UIKit
import Slidoo
class NavigationDrawerTransitionDelegate: NSObject, UIViewControllerTransitioningDelegate {
private let supportAnimation: Bool
init(supportAnimation: Bool) {
self.supportAnimation = supportAnimation
}
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return NavigationDrawerSwipeController(presentedViewController: presented, presenting: source)
}
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return NavigationDrawerPresentationAnimator(isBeingPresented: true, supportAnimation: supportAnimation)
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return NavigationDrawerPresentationAnimator(isBeingPresented: false, supportAnimation: supportAnimation)
}
}
Transition Delegate
使用 let presentedVC = DrawerViewController()
presentedViewControllerTransitionAnimator = nil
presentedViewControllerTransitionAnimator = NavigationDrawerTransitionDelegate(supportAnimation: supportAnimation)
presentedVC.transitioningDelegate = presentedViewControllerTransitionAnimator
presentedVC.modalPresentationStyle = .custom
present(presentedVC, animated: true)
当用户执行某些操作,如图标点击时,我们想要通过动画打开滑动视图或抽屉。使用上述代码在展示的视图控制器上设置过渡委托。
在屏幕滑动时打开滑动视图或抽屉
- 设置屏幕手势识别器
let screenEdgeGesture = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(didPan(panRecognizer:)))
screenEdgeGesture.edges = view.isRTL ? .right : .left
view.addGestureRecognizer(screenEdgeGesture)
- 检测滑动
@objc func didPan(panRecognizer: UIPanGestureRecognizer) {
switch panRecognizer.state {
case .began:
presentMenu(supportAnimation: false)
default:
forwardPanGesture(panRecognizer)
}
}
- 将手势识别器对象传递给自定义展示控制器
func forwardPanGesture(_ panRecognizer: UIPanGestureRecognizer) {
if let presentedVC = presentedViewController as? DrawerViewController, let presentationController = presentedVC.presentationController as? NavigationDrawerSwipeController {
presentationController.didPan(panRecognizer: panRecognizer, screenGestureEnabled: true)
}
}
安装
Slidoo 通过 CocoaPods 提供。要安装它,只需在 Podfile 中添加以下行
pod 'Slidoo'
作者
mitul_manish, [email protected]
许可
Slidoo 在 MIT 许可下提供。更多信息请参阅 LICENSE 文件。