extension OnlineDeviceListViewController {
//MARK: D - UICollectionViewDelegate
override func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
super.collectionView(collectionView, willDisplay: cell, forItemAt: indexPath)
// ========== 1. 统一处理 BaseDeviceUIItem 类型 ==========
if let item = cell as? BaseDeviceUIItem {
item.settingButton.removeTarget(nil, action: nil, for: .allEvents)
item.settingButton.addTarget(self, action: #selector(handleChannelShowMoreMenu(_:)), for: .touchUpInside)
}
// ========== 2. 底部圆角处理(仅最后一项)==========
let numberOfItems = collectionView.numberOfItems(inSection: indexPath.section)
cell.layer.mask = nil
if indexPath.item == numberOfItems - 1 {
let cornerLayer = CAShapeLayer()
let radius = kBorderRadius
let path = UIBezierPath(
roundedRect: cell.bounds,
byRoundingCorners: [.bottomLeft, .bottomRight],
cornerRadii: CGSize(width: radius, height: radius)
)
cornerLayer.path = path.cgPath
cornerLayer.frame = cell.bounds
cornerLayer.masksToBounds = true
cell.layer.mask = cornerLayer
}
// ========== 3. 特殊处理 OnlineDeviceCardNormalHeader ==========
guard let header = cell as? OnlineDeviceCardNormalHeader else { return }
// --- helpButton ---
header.ipcView.helpButton?.removeTarget(nil, action: nil, for: .allEvents)
header.ipcView.helpButton?.tag = indexPath.item
header.ipcView.helpButton?.addTarget(self, action: #selector(showHelp(_:)), for: .touchUpInside)
// --- collecAction ---
header.collecAction = { [weak self] (collect, device, channel, offset) in
guard let strongSelf = self else { return }
strongSelf.contentOffsetForNVRChannelCollect = offset
strongSelf.collectButtonClicked(isCollect: collect, device: device, channel: channel)
}
// --- channelSelected ---
header.channelSelected = { [weak self] (device, channel) in
guard let strongSelf = self else { return }
strongSelf.goToPreview(channel: channel, nvr: device)
}
// --- scrollCallback ---
header.scrollCallback = { [weak self] (visibles) in
guard let strongSelf = self else { return }
strongSelf.preconnectToRelay()
strongSelf.snapShotToVMS(isHorizontalScroll: true)
if let deviceId = strongSelf.deviceList[safe: indexPath.item]?.identifier {
var list = [TPSSDeviceId]()
for item in visibles {
let device = TPSSDeviceId()
device.deviceId = deviceId
device.channelID = item.row
list.append(device)
}
if list.count > 0 && (strongSelf.downloadPreviewSnapshotHorizontalScrollRequestID ?? 0) > 0 {
strongSelf.downloadSnapShotHorizontalVisiblePreviewHashMap[
strongSelf.downloadPreviewSnapshotHorizontalScrollRequestID!
] = list
}
}
}
// --- 恢复 contentOffset ---
let device = deviceList[indexPath.item]
if let offset = offsetDictionary[device.identifier],
offset.x + header.channelListVerticalCollectionView.frame.size.width - 2 * deviceListHorizontalMargin < header.channelListVerticalCollectionView.contentSize.width {
header.channelListVerticalCollectionView.contentOffset = offset
} else {
header.channelListVerticalCollectionView.contentOffset = CGPoint(x: 0, y: 0)
}
// 如果是收藏操作触发 reload,恢复之前的 offset
if collectDevice?.identifier == device.identifier && collectDevice?.deviceType == .NVR {
header.channelListVerticalCollectionView.contentOffset = contentOffsetForNVRChannelCollect ?? CGPoint.zero
}
// --- 圆角处理(折叠状态)---
if isFolded(at: indexPath.item) {
header.layer.masksToBounds = true
header.layer.cornerRadius = kBorderRadius
if #available(iOS 11.0, *) {
header.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner, .layerMaxXMaxYCorner]
}
} else {
header.layer.cornerRadius = 0
if #available(iOS 11.0, *) {
header.layer.cornerRadius = kBorderRadius
header.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
} else {
let corner = UIRectCorner(rawValue: UIRectCorner.topLeft.rawValue | UIRectCorner.topRight.rawValue)
setCornerForViewWithCorner(view: header, corner: corner, radius: kBorderRadius)
}
}
}
// MARK: - 移除 willDisplaySupplementaryView 或简化为仅处理非设备header
override func collectionView(_ collectionView: UICollectionView, willDisplaySupplementaryView view: UICollectionReusableView, forElementKind elementKind: String, at indexPath: IndexPath) {
super.collectionView(collectionView, willDisplaySupplementaryView: view, forElementKind: elementKind, at: indexPath)
view.indexPath = indexPath
// ⚠️ 只保留 VMS 分页加载逻辑(如果还有站点 header 才需要)
if appContext.isVmsLogin && !showLocalDeviceOnly {
let row = indexPath.section
if (row >= vmsDevices.count - 5 && !(showCollectPage ?
appContext.devicesIsLastPage(inVMSFavoriteSiteId: currentSubSiteInfo?.siteId ?? 0, devStatus: Int32(deviceOnlineStatus.rawValue)) :
appContext.devicesIsLastPage(inVMSSiteId: currentSubSiteInfo?.siteId ?? 0))) {
getNextPage()
}
}
// 如果你有其他类型的 header(如 OnlineDeviceListHeader),可以单独处理
if let item = view as? BaseDeviceUIItem {
item.settingButton.removeTarget(nil, action: nil, for: .allEvents)
item.settingButton.tag = indexPath.section
item.settingButton.addTarget(self, action: #selector(handleDeviceShowMoreMenu(_:)), for: .touchUpInside)
}
if let item = view as? BaseDeviceSDErrorItem {
item.sdErrorButton.removeTarget(nil, action: nil, for: .allEvents)
item.sdErrorButton.tag = indexPath.section
item.sdErrorButton.addTarget(self, action: #selector(sdCardErrorClicked(_:)), for: .touchUpInside)
}
if let item = view as? BaseDeviceBindItem {
item.bindButton.removeTarget(nil, action: nil, for: .allEvents)
item.bindButton.tag = indexPath.section
item.bindButton.addTarget(self, action: #selector(handleLocalDeviceBind(_:)), for: .touchUpInside)
}
// 处理分组 header 的圆角(比如站点 header)
if let item = view as? OnlineDeviceListHeader {
if isFolded(at: indexPath.section) {
item.layer.masksToBounds = true
item.layer.cornerRadius = kBorderRadius
} else {
item.layer.cornerRadius = 0
let corner = UIRectCorner(rawValue: UIRectCorner.topLeft.rawValue | UIRectCorner.topRight.rawValue)
setCornerForViewWithCorner(view: item, corner: corner, radius: kBorderRadius)
}
}
}
// MARK: - didEndDisplayingCell 替代 didEndDisplayingSupplementaryView
func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
// 记录 contentOffset 当 cell 滚出屏幕
guard collectionView.isDragging || collectionView.isDecelerating,
let header = cell as? OnlineDeviceCardNormalHeader,
indexPath.item < deviceList.count
else { return }
let offset = header.channelListVerticalCollectionView.contentOffset
let device = deviceList[indexPath.item]
offsetDictionary[device.identifier] = offset
}
}
// 原来的 supplementaryView 结束显示方法可删除或留空
@objc(collectionView:didEndDisplayingSupplementaryView:forElementOfKind:atIndexPath:)
func collectionView(_ collectionView: UICollectionView, didEndDisplayingSupplementaryView view: UICollectionReusableView, forElementOfKind elementKind: String, at indexPath: IndexPath) {
// 已由 cell 版本接管,此处可忽略
}
}
帮我完整修改这部分代码,现在报了很多错找不到Value of type 'OnlineDeviceListViewController' has no member 'deviceList'
最新发布