Files
ReadViewSDK/Sources/RDReaderView/ReaderView/RDReaderContentCell.swift
T
shenandshen 54798ba578 refactor: 添加中文注释 + 优化模块结构
- 给全部 78 个 Swift 源文件添加详细的中文注释(文件级、类级、方法级)
- 删除 LegacyRDReaderController/ 死代码目录(16 文件 4592 行)
- 根目录翻页容器文件移入 ReaderView/ 目录
- Resources/ 移入 EPUBCore/Resources/(与使用者归属一致)
- RDEPUBTextIndexTable.swift 移入 EPUBTextRendering/(消除反向依赖)
- RDURLReaderController.swift 移入 EPUBUI/(入口控制器归入 UI 层)
- 更新 podspec 资源路径
2026-05-25 10:19:14 +08:00

56 lines
2.0 KiB
Swift

//
// RDReaderContentCell.swift
// RDReaderDemo
//
// Created by yangsq on 2021/8/7.
//
// 文件职责:UICollectionViewCell 薄壳宿主,作为滚动模式下页面内容的容器。
// 该 cell 本身不包含业务逻辑,仅持有 containerView 并通过自动布局将其填满。
// 真正的内容视图由 RDReaderDataSource.pageContentView() 提供并赋值给 containerView。
//
// 架构位置:RDReaderView 四层架构中第三层的 cell 组件,被 UICollectionView 使用。
//
import UIKit
/// 内容 cell 薄壳宿主
/// 作为 UICollectionView 滚动模式下的页面容器。
/// 通过 ``containerView`` 属性持有实际内容视图,并在 layoutSubviews 中
/// 将内容视图的 frame 设置为与 contentView 等大,实现自动填满。
class RDReaderContentCell: UICollectionViewCell {
/// 内部持有的内容视图引用
private var _containerView: UIView? = nil
/// 内容视图属性
/// 设置时会自动将旧视图移除、新视图添加到 contentView 中
/// 读取时返回当前持有的内容视图
var containerView: UIView? {
set {
guard newValue !== _containerView else { return }
_containerView?.removeFromSuperview()
_containerView = newValue
if let containerView = _containerView {
contentView.addSubview(containerView)
setNeedsLayout()
}
}
get {
return _containerView
}
}
/// 布局子视图时调用
/// 将 containerView 的 frame 设置为与 contentView 等大,实现自动填满
override func layoutSubviews() {
super.layoutSubviews()
_containerView?.frame = CGRect(x: 0, y: 0, width: contentView.frame.width, height: contentView.frame.height)
}
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}