Skip to content

Commit

Permalink
modify FloatingViewDelegate and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
natai committed Jul 30, 2018
1 parent 85ba08a commit aa6588b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
4 changes: 2 additions & 2 deletions FloatingViewDemo/FloatingViewDemo/ViewController3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
1. 支持拖动、自动吸附、吸附后部分隐藏
2. 支持自定义可吸附的 edges
3. 支持自定义水平和纵向吸附的优先级
4. 支持自定义悬浮视图可到达区域
5. 支持自定义添加到`UIView`子类或者本库提供的`keyWindow`
4. 支持自定义开始吸附的最小距离
5. 支持自定义悬浮视图可到达区域
6. 支持自定义添加到`UIView`子类或者本库提供的`keyWindow`

# 环境要求

Expand Down Expand Up @@ -84,4 +85,16 @@ floatingView.makeFloatingWindowKeyAndVisible()

```swift
floatingView.updateFloatingWindowStatusBarStyle(to: default)
```
```

# 代理

在悬浮视图开始拖动、结束拖动、拖动中和完成部分隐藏动画时,分别有以下代理方法:

```swift
func floatingViewDidBeginDragging(panGestureRecognizer: UIPanGestureRecognizer)
func floatingViewDidEndDragging(panGestureRecognizer: UIPanGestureRecognizer)
func floatingViewDidMove(panGestureRecognizer: UIPanGestureRecognizer)
func floatingViewFinishedPartiallyHideAnimation()
```

16 changes: 8 additions & 8 deletions Source/FloatingViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }
}
8 changes: 4 additions & 4 deletions Source/UIView+Floating.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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()
}
}
}

0 comments on commit aa6588b

Please sign in to comment.