https://github.com/pujiaxin33/jxpopupview
一个轻量级的自定义视图弹出框架
https://github.com/pujiaxin33/jxpopupview
alert dialog display pop popover popup
Last synced: about 1 year ago
JSON representation
一个轻量级的自定义视图弹出框架
- Host: GitHub
- URL: https://github.com/pujiaxin33/jxpopupview
- Owner: pujiaxin33
- License: mit
- Created: 2018-10-22T10:17:03.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-07-08T07:37:03.000Z (about 2 years ago)
- Last Synced: 2025-05-09T00:01:55.939Z (about 1 year ago)
- Topics: alert, dialog, display, pop, popover, popup
- Language: Swift
- Size: 920 KB
- Stars: 153
- Watchers: 5
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JXPopupView
一个轻量级的自定义视图弹出框架,可灵活配置动画、背景风格。
# 特性
- 默认提供丰富的动画效果,而且可以灵活的扩展配置,只要遵从并实现`PopupViewAnimator`协议即可;
- 使用范围更广,通过view封装,可以在任何view上面展示,并不局限于UIViewController;
- 弹框背景配置灵活,借鉴了`MBProgressHUD`对背景视图的处理逻辑;
- 交互细节可配置,提供了`isDismissible`、`isInteractive`、`isPenetrable`属性进行配置;
# 预览
## 动画效果
动画效果 | GIF
----------|--------------
| 渐隐渐现 |  |
| 缩放 |  |
| 往左 |  |
| 往右 |  |
| 往下 |  |
| 往上 |  |
| 弹性动画 |  |
| 完全自定义动画 |  |
## Layout布局方式
动画效果 | GIF
----------|--------------
| Top顶部 |  |
| Bottom底部 |  |
| Leading前部 |  |
| Trailing尾部 |  |
| Center | 居中(无示意图) |
| Frame | 自定义frame(无示意图) |
## 背景风格
背景风格 | GIF
----------|--------------
| 固定色值 |  |
| blur light |  |
| blur dark |  |
## 指定containerView
指定containerView | GIF
----------|--------------
| Window |  |
| UIViewController.view |  |
| CustomView |  |
# 要求
iOS: 9+
XCode: 12.1+
swift: 5.0+
# 安装
## CocoaPods
在Podfile文件里面添加
```
pod 'JXPopupView'
```
然后再pod install(最好先pod update)
# 使用
```
//- 确定contentView的布局方式
enum Layout {
case center(Center)
case top(Top)
case bottom(Bottom)
case leading(Leading)
case trailing(Trailing)
case frame(CGRect)
}
//如果contentView重载了intrinsicContentSize属性并返回其内容的CGSize,就无需再设置width、height值。
let layout: BaseAnimator.Layout = .center(.init(offsetY: 0, offsetX: 0, width: 200, height: 200))
//- 确定动画效果
let animator = FadeInOutAnimator(layout: layout)
//- 初始化JXPopupView
let contentView = TestAlertView()
let popupView = JXPopupView(containerView: containerView, contentView: contentView, animator: animator)
//- 配置交互
popupView.isDismissible = true
popupView.isInteractive = true
popupView.isPenetrable = false
//- 配置背景
popupView.backgroundView.style = self.backgroundStyle
popupView.backgroundView.blurEffectStyle = self.backgroundEffectStyle
popupView.backgroundView.color = self.backgroundColor
//- 展示popupView
popupView.display(animated: true, completion: nil)
//- 消失popupView
//通过extension提供的popupView方法,获取JXPopupView进行操作,可以不用全局持有JXPopupView属性
contentView.popupView()?.dismiss(animated: true, completion: nil)
```
# 动画自定义
## `PopupViewAnimator`协议方法
```
/// 初始化配置动画驱动器
///
/// - Parameters:
/// - popupView: PopupView
/// - contentView: 自定义的弹框视图
/// - backgroundView: 背景视图
/// - Returns: void
func setup(popupView: PopupView, contentView: UIView, backgroundView: PopupView.BackgroundView)containerView: UIView)
/// 处理展示动画
///
/// - Parameters:
/// - contentView: 自定义的弹框视图
/// - backgroundView: 背景视图
/// - animated: 是否需要动画
/// - completion: 动画完成后的回调
/// - Returns: void
func display(contentView: UIView, backgroundView: JXBackgroundView, animated: Bool, completion: @escaping ()->())
/// 处理消失动画
///
/// - Parameters:
/// - contentView: 自定义的弹框视图
/// - backgroundView: 背景视图
/// - animated: 是否需要动画
/// - completion: 动画完成后的回调
func dismiss(contentView: UIView, backgroundView: JXBackgroundView,animated: Bool, completion: @escaping ()->())
```
## 自定义动画建议
- 完全自定义动画
可以继承`BaseAnimator`或者自己新建一个类,遵从`PopupViewAnimator`协议,实现对应方法即可。参考demo工程的`BaseAnimator`类
# 证书
JXPopupView is available under the MIT license. See the LICENSE file for more info.