Latest 2.0.0
Homepage https://github.com/Jason-Stan-Lee/JSLTransitionLib
License MIT
Platforms ios 9.0
Authors

JSLTransitionLib

CI Status
Version
License
Platform

该库集成了转场手势管理、转场代理以及交互转场进度控制,使接入方更关注动画细节,不关心转场相关的基础开发。可以使不了解自定义转场内部细节的开发人员也能迅速上手

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

JSLTransitionLib is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'JSLTransitionLib'

Author

[email protected]

License

JSLTransitionLib is available under the MIT license. See the LICENSE file for more info.

使用方式

模态转场

支持交互 Dismiss 与 Present

  • 设置视图控制器转场代理
    
    // 设置单独视图控制器转场代理,不与其他视图控制器共用
    let customTransitionVC = UIViewController()
    customTransitionVC.presentationTransitioningDelegateS = ViewControllerTransitionDelegate(presentedViewController: customTransitionVC)

// 导航视图控制器,其子视图控制器共用同一转场代理,每个子视图控制器可以配置特有的转场动画,也可以由其父视图控制器统一配置其所有子视图的统一动画
let customTransitionNC = UINavigationController()
customTransitionNC.presentationTransitioningDelegateS = ViewControllerTransitionDelegate(presentedViewController: customTransitionNC)

// 工具栏控视图制器,其子视图控制器可以有自己独有的转场动画
let customTransitionTC = UITabBarController()
customTransitionTC.presentationTransitioningDelegateS = ViewControllerTransitionDelegate(presentedViewController: customTransitionTC)

- 配置自定义转场动画

// 在需要自定义转场动画的视图控制器中 override 该方法,根据不同转场类型,return 对应的动画,nil 则使用对应类型的默认动画
func viewControllerAnimatedTransitioning(for transitionType: TransitioningType) -> BasicViewControllerAnimatedTransitioning?

// 可以根据自定义转场动画的需要 return UIPresentationController 的子类, nil 为默认
func presentationController(for presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController?

// 返回在当前页面,「交互推出」的下一个视图控制器,nil 为不响应 presnetTo 手势事件
func viewControllerForInteractivePresentTo() -> UIViewController?

- 交互转场控制

/ 设置指定页面是否支持交互转场 /
/// 是否允许交互 Dismiss
var isInteractiveDismissEnable: Bool { get set }
/// 是否允许交互 Present to 新页面
var isInteractivePresentToEnable: Bool { get set }

/ 设置转场手势的触发逻辑「手势触发的位置」、「手势触发的方向」 /

/// 是否接收交互转场手势,返回 false 取消
func interactiveTransitionGestureShouldReceive(touch: UITouch) -> Bool

/// 根据手势滑动的位移、区分具体的转场类型,禁止转场返回 TransitioningType.none
func interactiveTransitionType(for location: CGPoint, translation: CGPoint) -> TransitioningType

/ 交互转场过程中的进度控制,location 和 translation 是每次触发手势事件的「阶段: fraction」位置和平移距离 /
/// 位移和起始位置,返回进度
func interactiveTransitionCompletePercent(for transitionType: TransitioningType,
location: CGPoint,
translation: CGPoint) -> CGFloat

/// 与转场交互手势冲突时,是否可以同时进行,比如:上滑手势同时,页面的 scrollView 滚动等
func interactiveGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer, for transitionType: TransitioningType) -> Bool

- 交互转场过程

/// 是否正在 Dismiss 交互
var isInteractiveDismissing: Bool { get }
/// 是否正在交互 Present to 新页面
var isInteractivePresentTo: Bool { get }

/// 是否正在转场,包含交互转场和非交互转场
var isTransitioning: Bool { get }

/// 开始
func startInteractive(for transitionType: TransitioningType)
/// 完成
func finishInteractive(for transitionType: TransitioningType)
/// 取消
func cancelInteractive(for transitionType: TransitioningType)

#### 导航转场
目前只支持交互 Dismiss,暂不支持交互 Push

- 设置视图控制器转场代理

// 设置单独视图控制器转场代理,不与其他视图控制器共用
let customTransitionVC = UIViewController()
customTransitionVC.navigationTransitioningDelegate = NavigationTransitioningDelegate(navigationController: customTransitionVC)

// 导航视图控制器,其子视图控制器共用同一转场代理,每个子视图控制器可以配置特有的转场动画,也可以由其父视图控制器统一配置其所有子视图的统一动画
let customTransitionNC = UINavigationController()
customTransitionNC.navigationTransitioningDelegate = NavigationTransitioningDelegate(navigationController: customTransitionNC)

// 工具栏控视图制器,其子视图控制器可以有自己独有的转场动画
let customTransitionTC = UITabBarController()
customTransitionTC.navigationTransitioningDelegate = NavigationTransitioningDelegate(navigationController: customTransitionTC)

- 配置自定义转场动画

/// 根据 operation 转场动画, nil 为默认动画, 可重载返回定义转场动画
///
/// – Parameters:
/// – forOperation: 转场方式
/// – interactive: 是否为交互 pop
/// – Returns: 转场动画, nil 为默认
func navigationControllerAnimatedTransitioning(forOperation: UINavigationController.Operation, interactive: Bool) -> BasicViewControllerAnimatedTransitioning?

- 交互转场控制

/ 设置指定页面是否支持交互转场 /
/// 是否允许交互 Dismiss
var isInteractivePopEnabled: Bool { get set }

/ 设置转场手势的触发逻辑「手势触发的位置」、「手势触发的方向」 /

/// 开始收到交互手势
///
/// – Parameter touch: 手势
/// – Returns: 返回 false 取消交互, 默认 true
func interactivePopGestureShouldReceive(touch: UITouch) -> Bool

/// 开始移动手势
///
/// – Parameter translation: 位移
/// – Returns: 返回 false 取消交互, 默认 true
func interactivePopGestureShouldBegin(translation: CGPoint) -> Bool

/// 通过位移和开始位置,计算 pop 的进度
///
/// – Parameters:
/// – translation: 位移
/// – startPoint: 开始位置
/// – Returns: 完成进度 0 ~ 1
func navigationInteractivePopCompletePercent(forTranslation: CGPoint,
startPoint: CGPoint) -> CGFloat

- 交互转场过程

/// 是否正在交互 pop
var isInteractivePoping: Bool { get }

/// 是否正在过渡动画
var isNavigationTransitioning: Bool { get }

/// 开始
func startInteractivePop()
/// 完成
func finishInteractivePop()
/// 取消
func cancleInteractivePop()

Latest podspec

{
    "name": "JSLTransitionLib",
    "version": "2.0.0",
    "summary": "Help you to hold custom view transitions EASYLY !",
    "swift_version": "4.2",
    "platforms": {
        "ios": "9.0"
    },
    "description": "u8be5u5e93u96c6u6210u4e86u8f6cu573au624bu52bfu7ba1u7406u3001u8f6cu573au4ee3u7406u4ee5u53cau4ea4u4e92u8f6cu573au8fdbu5ea6u63a7u5236uff0cu4f7fu63a5u5165u65b9u66f4u5173u6ce8u52a8u753bu7ec6u8282uff0cu4e0du5173u5fc3u8f6cu573au76f8u5173u7684u57fau7840u5f00u53d1u3002u53efu4ee5u4f7fu4e0du4e86u89e3u81eau5b9au4e49u8f6cu573au5185u90e8u7ec6u8282u7684u5f00u53d1u4ebau5458u4e5fu80fdu8fc5u901fu4e0au624b",
    "homepage": "https://github.com/Jason-Stan-Lee/JSLTransitionLib",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "[email protected]": "Jason-Stan-Lee"
    },
    "source": {
        "git": "https://github.com/Jason-Stan-Lee/JSLTransitionLib.git",
        "tag": "2.0.0"
    },
    "source_files": "JSLTransitionLib/Classes/**/*"
}

Pin It on Pinterest

Share This