- 实现EPUB阅读器搜索功能及选中注释功能 - 优化CFI模块,修复代码审查发现的11个问题 - 实现大书远距目录跳转与后台补全优化方案 - 优化设置面板与章节运行时联动 - 重构及大量改进优化
43 lines
1.8 KiB
Swift
43 lines
1.8 KiB
Swift
|
|
import UIKit
|
|
|
|
extension RDReaderView: UICollectionViewDataSource, RDReaderFlowLayoutDelegate, RDReaderFlowLayoutDataSoure {
|
|
|
|
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
|
if let identifer = pageReuseIdentifier(for: indexPath.row) {
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifer, for: IndexPath(item: indexPath.row, section: 0)) as! RDReaderContentCell
|
|
let preloadedView = preloadController.takePreloadedView(for: indexPath.row)
|
|
let reusableView = cell.containerView ?? preloadedView
|
|
cell.containerView = contentViewForPage(indexPath.row, reusableView: reusableView)
|
|
|
|
if pageDirection == .rightToLeft && currentDisplayType != .verticalScroll {
|
|
cell.contentView.transform = CGAffineTransform(scaleX: -1, y: 1)
|
|
} else {
|
|
cell.contentView.transform = .identity
|
|
}
|
|
return cell
|
|
}
|
|
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(UICollectionViewCell.self), for: indexPath)
|
|
|
|
return cell
|
|
}
|
|
|
|
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return numberOfPages()
|
|
}
|
|
|
|
public func pageNum(flowLayout: RDReaderFlowLayout, pageIndex: Int) {
|
|
if currentPage >= 0, currentPage != pageIndex {
|
|
predictedPageDirection = pageIndex >= currentPage
|
|
}
|
|
currentPage = pageIndex
|
|
primePageCache(around: pageIndex, preferredForward: predictedPageDirection)
|
|
}
|
|
|
|
public func heigtOfVerticalScrollPage(flowLayout: RDReaderFlowLayout, pageIndex: Int) -> CGFloat? {
|
|
return nil
|
|
}
|
|
}
|