- 实现EPUB阅读器搜索功能及选中注释功能 - 优化CFI模块,修复代码审查发现的11个问题 - 实现大书远距目录跳转与后台补全优化方案 - 优化设置面板与章节运行时联动 - 重构及大量改进优化
69 lines
2.8 KiB
Swift
69 lines
2.8 KiB
Swift
|
||
import UIKit
|
||
|
||
extension RDReaderView {
|
||
|
||
public func register(contentView: UIView.Type, contentViewWithReuseIdentifier identifier: String) {
|
||
contentViews[identifier] = contentView
|
||
collectionView.register(RDReaderContentCell.self, forCellWithReuseIdentifier: identifier)
|
||
}
|
||
|
||
public func dequeueReusableContentView(withReuseIdentifier identifier: String, for pageNum: Int) -> UIView {
|
||
if self.currentDisplayType != .pageCurl, let cell = self.collectionView.cellForItem(at: IndexPath(row: pageNum, section: 0)) as? RDReaderContentCell, let containerView = cell.containerView {
|
||
return containerView
|
||
}
|
||
let contentViewClass = contentViews[identifier]
|
||
assert(contentViewClass != nil, "请调用register(contentView:contentViewWithReuseIdentifier:)")
|
||
let contentView = contentViewClass!.init()
|
||
return contentView
|
||
}
|
||
|
||
public func pageContentView(pageNum: Int) -> UIView? {
|
||
if currentDisplayType == .pageCurl {
|
||
return (self.pageViewController.viewControllers?.first as? RDReaderPageChildViewController)?.contentView
|
||
} else {
|
||
let cell = collectionView.cellForItem(at: IndexPath(item: pageNum, section: 0)) as? RDReaderContentCell
|
||
return cell?.containerView
|
||
}
|
||
}
|
||
|
||
public func resolvedSinglePageSize(pageNum: Int? = nil) -> CGSize {
|
||
let targetPage = pageNum ?? (currentPage >= 0 ? currentPage : nil)
|
||
if let targetPage,
|
||
let contentView = pageContentView(pageNum: targetPage),
|
||
contentView.bounds.width > 0,
|
||
contentView.bounds.height > 0 {
|
||
return contentView.bounds.size
|
||
}
|
||
|
||
if currentDisplayType == .pageCurl {
|
||
if let childViewController = pageViewController.viewControllers?.first as? RDReaderPageChildViewController,
|
||
childViewController.view.bounds.width > 0,
|
||
childViewController.view.bounds.height > 0 {
|
||
return childViewController.view.bounds.size
|
||
}
|
||
if pageViewController.view.bounds.width > 0, pageViewController.view.bounds.height > 0 {
|
||
return pageViewController.view.bounds.size
|
||
}
|
||
return bounds.size
|
||
}
|
||
|
||
let containerBounds = collectionView.bounds.size == .zero ? bounds.size : collectionView.bounds.size
|
||
guard containerBounds.width > 0, containerBounds.height > 0 else {
|
||
return bounds.size
|
||
}
|
||
|
||
switch currentDisplayType {
|
||
case .horizontalScroll:
|
||
return CGSize(
|
||
width: containerBounds.width / CGFloat(max(pagesPerScreen, 1)),
|
||
height: containerBounds.height
|
||
)
|
||
case .verticalScroll:
|
||
return containerBounds
|
||
case .pageCurl:
|
||
return bounds.size
|
||
}
|
||
}
|
||
}
|