子视图控制器框架,使设置父控制器像馅饼一样简单
描述
Family 是一个子视图控制器框架,它使设置父控制器像馅饼一样简单。借助简单而强大的公共 API,您可以在不损失可维护性的情况下构建复杂的布局,让您专注于重要的事情:让您的应用程序流行起来,让您的业务逻辑大放异彩。
构建此框架是为了更轻松地构建和维护父控制器(也称为流控制器)。使用子视图控制器可以使代码更加模块化、灵活和可测试。它解决了原版方法的最大缺点之一:如何在保持出队不变的同时获得连续滚动体验?
这就是家庭框架的用武之地。借助其布局算法,所有常规视图和滚动视图都按照您添加到层次结构的相同线性垂直顺序堆叠。若要实现连续滚动视图,子滚动视图不再滚动自己,而是通过父滚动视图(框架为您处理)将他们的新内容偏移量传递给他们。该框架还会动态修改视图的框架,从而限制窗口的高度。
家庭背后的故事
如果您对家庭背后的起源故事感兴趣,那么您可以阅读这篇 Medium 文章。
特征
- ? 动画支持。
- ??具有多个滚动视图的连续滚动。
- ? 子视图控制器之间的边距。
- ? 表视图和集合视图出列。
- ? 支持视图之间的自定义间距。
- ? 支持苹果。
- ? 支持macOS。
- ?? 电视操作系统支持。
Supporting the project
If you want to support the development of this framework, you can do so by becoming a sponsor. ❤️
Usage
The new public API:
body(withDuration: 0) {
add(detailViewController)
.background(.view(backgroundView))
.padding(.init(top: 20, left: 20, bottom: 20, right: 20))
.margin(.init(top: 20, left: 0, bottom: 20, right: 0))
}
Add a regular child view controller:
let familyController = FamilyViewController()
let viewController = UIViewController()
familyController.addChild(viewController)
Add a child view controller constrained by height:
let familyController = FamilyViewController()
let viewController = UIViewController()
familyController.addChild(viewController, height: 175)
Add a child view controller with a custom view on the controller:
let familyController = FamilyViewController()
let customController = CustomViewController()
// This will add the scroll view of the custom controller
// instead of the controllers view.
familyController.addChild(customController, view: { $0.scrollView })
Move a view controller:
familyController.moveChild(customController, to: 1)
Perform batch updates (it is encouraged to use performBatchUpdates when updaing more than one view controller):
familyController.performBatchUpdates({ controller in
controller.addChild(controller1)
controller.addChild(controller2)
controller.moveChild(controller2, to: 0)
controller3.removeFromParent()
})
Adding animations
When adding animations, not that you have to give them a key.
let basicAnimation = CABasicAnimation()
basicAnimation.duration = 0.5
controller.view.layer.add(springAnimation, forKey: "Basic Animations")
let springAnimation = CASpringAnimation()
springAnimation.damping = 0.6
springAnimation.initialVelocity = 0.6
springAnimation.mass = 0.4
springAnimation.duration = 0.6
springAnimation.isRemovedOnCompletion = false
controller.view.layer.add(springAnimation, forKey: "Spring Animations")
Installation
Family is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Family'
and then run
pod install
Family is also available through Carthage. To install just write into your Cartfile:
github "zenangst/Family"
and then run
carthage install
When it’s finished, install the built framework (which can be found in the folder) into your Xcode project.Carthage/Build
Family can also be installed manually. Just download and drop folders in your project.Sources
Author
Christoffer Winterkvist, [email protected]
Contributing
We would love you to contribute to Family, check the CONTRIBUTING file for more info.
Credits
- hyperoslo’s Spots uses the same kind of implementation in order to render its component.
- Ole Begemanns implementation of OLEContainerScrollView is the basis for , we salute you. Reference: http://oleb.net/blog/2014/05/scrollviews-inside-scrollviews/
SpotsScrollView
License
Family is available under the MIT license. See the LICENSE file for more info.