Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A protocol make your view floating and draggable

License

NotificationsYou must be signed in to change notification settings

Natai/FloatingViewProtocol

Repository files navigation

  1. 支持拖动、自动吸附、吸附后部分隐藏
  2. 支持自定义可吸附的 edges
  3. 支持自定义水平和纵向吸附的优先级
  4. 支持自定义开始吸附的最小距离
  5. 支持自定义悬浮视图可到达区域
  6. 支持自定义添加到UIView子类或者本库提供的keyWindow

环境要求

  • iOS 8.0+
  • Swift 5.0

安装

Cocoapods

Podfile添加:

pod 'FloatingViewProtocol'

使用

简单运用

  1. 遵守FloatingViewProtocol协议

  2. 实现component属性

  3. 调用addFloatingPanGestureRecognir()方法添加拖动手势

此时悬浮视图已经支持拖动和自动吸附。水平默认超过屏幕中点,纵向默认距离屏幕边缘小于 100 时即可吸附。

自定义

在简单运用的基础上,可在悬浮视图中重写各种属性:

classFloatingView:UIView,FloatingViewProtocol{    /// 是否可以拖拽varisDraggable=true    /// 是否自动吸附varisAutoAdsorb=true    /// 可自动吸附的方向varadsorbableEdges:FloatingAdsorbableEdges=[.left,.right]    /// 水平方向吸附和垂直方向吸附的优先级varadsorbPriority:FloatingAdsorbPriority=.equal    /// 吸附动画时间varadsorbAnimationDuration:TimeInterval=0.35    /// 停止拖拽后,最小距离 floatingEdge 边缘多少可以自动吸附varminAdsorbableSpacings:UIEdgeInsets=UIEdgeInsets(top:100, left:50, bottom:100, right:50)    /// 吸附在边缘后是否自动地部分隐藏varisAutoPartiallyHide=true    /// 隐藏的百分比varpartiallyHidePercent:CGFloat=0.3    /// 部分隐藏动画时长varpartiallyHideAnimationDuration:TimeInterval=0.35    /// 悬浮视图可到达区域,距离父视图各边的缩进varfloatingEdgeInsets:UIEdgeInsets=UIEdgeInsets(top:10, left:10, bottom:10, right:10)}

此外当悬浮视图已经添加到父视图后,还可以对悬浮视图对象的属性直接赋值修改以上特性。

父视图

悬浮视图可以直接添加到普通的UIView子类中,也可以添加到新建的keyWindow中。

添加到普通UIView子类:

navigationController?.view.addSubview(floatingView)

添加到新建的keyWindow

floatingView.makeFloatingWindowKeyAndVisible()

对于直接添加到keyWindow中的悬浮视图,可以动态更改keyWindow根视图的状态栏样式:

floatingView.updateFloatingWindowStatusBarStyle(to: default)

代理

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

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

About

A protocol make your view floating and draggable

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp