Jelly是一个用于.animate、非交互式和交互式.viewcontroller转换和呈现的库,重点是一个简单而灵活的API。
通过几行源代码,可以创建交互式UIzcze视图控制器转换和自定义可调整大小的UInze视图控制器呈现,而不必使用繁琐的UIKit Transitioning API。
使用原生
函数。
不要忘了保持Presentation
var slidePresentation = SlidePresentation(direction: .left)
let animator = Animator(presentation: slidePresentation)
animator.prepare(viewController: viewController)
present(viewController, animated: true, completion: nil)
- 对象
- Configure an
Animator
with the Presentation - 函数。
- 调用原生
class ViewController : UIViewController {
var animator: Jelly.Animator?
override func viewDidLoad() {
super.viewDidLoad()
let viewController = YourViewController()
let presentation = SlidePresentation(direction: .left)
animator = Animator(presentation:presentation)
animator?.prepare(presentedViewController: viewController)
present(viewController, animated: true, completion: nil)
}
}
保持强烈的
由于transitioningDelegate
是弱引用,因此您需要在您要呈现的UIViewController
内部或维护您呈现的中心对象中保持对Animator
的强引用。
交互式过渡可以用于滑和覆盖转换。如果转换是交互式的,则需要传递一个InteractionConfiguration
对象到呈现中。
这里有三个参数扮演了重要的角色。首先是completionThreshold
,它决定了动画完成的部分,即当用户完成的交互达到多少百分比时,动画会自动完成。第二个参数是实际交互类型。Jelly提供了.edge
和.canvas
类型。在.edge
转换中,用户必须从屏幕边缘执行手势。当使用.canvas
类型时,配置了手势识别器,以便直接与呈现视图和被呈现视图交互,从而导致转换。最后一个参数是所谓的mode
。使用模式,您可以限制交互到呈现或消失交互(默认值为[.present,.dismiss]
)。
let viewController = YourViewController()
let interaction = InteractionConfiguration(presentingViewController: self, completionThreshold: 0.5, dragMode: .edge, mode: .dismiss)
let presentation = SlidePresentation(direction: .right, interactionConfiguration: interaction)
let animator = Animator(presentation: presentation)
animator.prepare(presentedViewController: viewController)
Jelly 2.0还提供了一个名为LIVE UPDATE的新特性。使用Jelly的Live Update API
,现在可以在视图控制器已经可见时更新alignment
、size
、margin-guards
和corner radius
。
这些是Animator提供的新的实时更新功能。
updateAlignment(alignment: PresentationAlignment, duration: Duration)
- 覆盖和淡入淡出updateVerticalAlignment(alignment: VerticalAlignment, duration: Duration)
- 覆盖和淡入淡出updateHorizontalAlignment(alignment: HorizontalAlignment, duration: Duration)
- 覆盖和淡入淡出updateSize(presentationSize: PresentationSize, duration: Duration)
- 覆盖和淡入淡出updateWidth(width: Size, duration: Duration)
- 覆盖、淡入淡出和水平滑动updateHeight(height: Size, duration: Duration)
- 覆盖、淡入淡出和垂直滑动updateMarginGuards(marginGuards: UIEdgeInsets, duration: Duration)
- 覆盖和淡入淡出updateCorners(radius: CGFloat, corners: CACornerMask, duration: Duration)
- 覆盖、淡入淡出和滑动
对于不支持 presentationType 的情况,使用它们可能会引发异常。
例如:目前无法在幻灯片演示文稿中更新大小。
演示类型可以通过各种设置进行配置
大小
边距保护
方向
水平和垂直对齐
暗淡和模糊的背景样式
持续时间
演示和消失曲线
弹簧阻尼和速度
角落规格
&角落半径
完成阈值
交互式拖拽模式
(边缘或平移)交互模式
(演示、消失)视差
(仅在幻灯片演示中可用)
每个组件的详细信息可以在 Jelly Wiki 中找到。
您的应用部署目标为 >= iOS 11.0
Jelly 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'Jelly', '~> 2.2.2'
或使用 SPM
-
在 iOS Dev Weekly 中被 @Dave Verwer 特色提及 - 问题编号 112
-
在 This Week in Swift 中被 @Natasha the Robot 特色提及 - 问题编号 279
Sebastian Boldt, https://www.sebastianboldt.com
我是一名专注于 iOS 的移动软件架构师和开发者。热衷于创建令人惊叹的用户体验、设计美丽的用户界面,并编写可维护、结构化和面向最佳实践的代码。不断尝试提高技能并学习新技术。
Jelly 遵循 MIT 许可证。详见 LICENSE 文件以获取更多信息。