- 新增字体选择(系统/宋体/圆体/等宽)与暗色图片柔化配置 - 文本选择改为自定义手势+操作栏(拷贝/高亮/批注) - 添加 accessibilityIdentifier 支持自动化 UI 测试 - 新增 UITests 覆盖阅读器打开/关闭、工具栏、设置面板、批注等 - 添加 Demo 测试用 EPUB 书源(宝山辽墓材料与释读) - 新增文档:UI 自动化测试、功能开发计划、阅读器规划
57 lines
2.0 KiB
Swift
57 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)
|
||
accessibilityIdentifier = "epub.reader.content.cell"
|
||
}
|
||
required init?(coder: NSCoder) {
|
||
fatalError("init(coder:) has not been implemented")
|
||
}
|
||
}
|