From aa6588bdef646b18479944b212eb1533c40feef8 Mon Sep 17 00:00:00 2001 From: natai <> Date: Mon, 30 Jul 2018 11:06:07 +0800 Subject: [PATCH] modify FloatingViewDelegate and update README --- .../FloatingViewDemo/ViewController3.swift | 4 ++-- README.md | 19 ++++++++++++++++--- Source/FloatingViewDelegate.swift | 16 ++++++++-------- Source/UIView+Floating.swift | 8 ++++---- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/FloatingViewDemo/FloatingViewDemo/ViewController3.swift b/FloatingViewDemo/FloatingViewDemo/ViewController3.swift index 325ee56..5575b2d 100644 --- a/FloatingViewDemo/FloatingViewDemo/ViewController3.swift +++ b/FloatingViewDemo/FloatingViewDemo/ViewController3.swift @@ -117,11 +117,11 @@ extension ViewController3: UITextFieldDelegate { // MARK: - FloatingViewDelegate extension ViewController3: FloatingViewDelegate { - func floatingViewDidBeginDragging(_ floatingView: (UIView & FloatingViewProtocol)) { + func floatingViewDidBeginDragging(panGestureRecognizer: UIPanGestureRecognizer) { floatingView.alpha = 1 } - func floatingViewFinishedPartiallyHideAnimation(_ floatingView: (UIView & FloatingViewProtocol)) { + func floatingViewFinishedPartiallyHideAnimation() { floatingView.alpha = 0.5 } } diff --git a/README.md b/README.md index 49e027c..a34ae31 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,9 @@ 1. 支持拖动、自动吸附、吸附后部分隐藏 2. 支持自定义可吸附的 edges 3. 支持自定义水平和纵向吸附的优先级 -4. 支持自定义悬浮视图可到达区域 -5. 支持自定义添加到`UIView`子类或者本库提供的`keyWindow`上 +4. 支持自定义开始吸附的最小距离 +5. 支持自定义悬浮视图可到达区域 +6. 支持自定义添加到`UIView`子类或者本库提供的`keyWindow`上 # 环境要求 @@ -84,4 +85,16 @@ floatingView.makeFloatingWindowKeyAndVisible() ```swift floatingView.updateFloatingWindowStatusBarStyle(to: default) -``` \ No newline at end of file +``` + +# 代理 + +在悬浮视图开始拖动、结束拖动、拖动中和完成部分隐藏动画时,分别有以下代理方法: + +```swift +func floatingViewDidBeginDragging(panGestureRecognizer: UIPanGestureRecognizer) +func floatingViewDidEndDragging(panGestureRecognizer: UIPanGestureRecognizer) +func floatingViewDidMove(panGestureRecognizer: UIPanGestureRecognizer) +func floatingViewFinishedPartiallyHideAnimation() +``` + diff --git a/Source/FloatingViewDelegate.swift b/Source/FloatingViewDelegate.swift index d426989..94dcadf 100644 --- a/Source/FloatingViewDelegate.swift +++ b/Source/FloatingViewDelegate.swift @@ -9,15 +9,15 @@ import UIKit public protocol FloatingViewDelegate: NSObjectProtocol { - func floatingViewDidBeginDragging(_ floatingView: (UIView & FloatingViewProtocol)) - func floatingViewDidEndDragging(_ floatingView: (UIView & FloatingViewProtocol)) - func floatingViewDidMove(_ floatingView: (UIView & FloatingViewProtocol)) - func floatingViewFinishedPartiallyHideAnimation(_ floatingView: (UIView & FloatingViewProtocol)) + func floatingViewDidBeginDragging(panGestureRecognizer: UIPanGestureRecognizer) + func floatingViewDidEndDragging(panGestureRecognizer: UIPanGestureRecognizer) + func floatingViewDidMove(panGestureRecognizer: UIPanGestureRecognizer) + func floatingViewFinishedPartiallyHideAnimation() } public extension FloatingViewDelegate { - func floatingViewDidBeginDragging(_ floatingView: (UIView & FloatingViewProtocol)) { } - func floatingViewDidEndDragging(_ floatingView: (UIView & FloatingViewProtocol)) { } - func floatingViewDidMove(_ floatingView: (UIView & FloatingViewProtocol)) { } - func floatingViewFinishedPartiallyHideAnimation(_ floatingView: (UIView & FloatingViewProtocol)) { } + func floatingViewDidBeginDragging(panGestureRecognizer: UIPanGestureRecognizer) { } + func floatingViewDidEndDragging(panGestureRecognizer: UIPanGestureRecognizer) { } + func floatingViewDidMove(panGestureRecognizer: UIPanGestureRecognizer) { } + func floatingViewFinishedPartiallyHideAnimation() { } } diff --git a/Source/UIView+Floating.swift b/Source/UIView+Floating.swift index d1be3f5..10bb7d5 100644 --- a/Source/UIView+Floating.swift +++ b/Source/UIView+Floating.swift @@ -43,17 +43,17 @@ public extension UIView { switch pan.state { case .began: - floatingDelegate?.floatingViewDidBeginDragging(view) + floatingDelegate?.floatingViewDidBeginDragging(panGestureRecognizer: pan) case .changed: defer { pan.setTranslation(.zero, in: self) } let translation = pan.translation(in: self) modifyOrigin(withTranslation: translation) - floatingDelegate?.floatingViewDidMove(view) + floatingDelegate?.floatingViewDidMove(panGestureRecognizer: pan) case .ended: animateToAdsorb() - floatingDelegate?.floatingViewDidEndDragging(view) + floatingDelegate?.floatingViewDidEndDragging(panGestureRecognizer: pan) default: break } } @@ -165,7 +165,7 @@ public extension UIView { UIView.animate(withDuration: view.partiallyHideAnimationDuration, animations: { self.frame.origin = destinationOrigin }) { isFinished in - self.floatingDelegate?.floatingViewFinishedPartiallyHideAnimation(view) + self.floatingDelegate?.floatingViewFinishedPartiallyHideAnimation() } } }