Explorar o código

1,ui 调整 2,分类选中后移动到中间

jsonwang %!s(int64=4) %!d(string=hai) anos
pai
achega
bb82f945bb

+ 9 - 5
MusicVideoPlus/MusicVideoPlus/Classes/Modules/Home/Controllers/MVHomeController.swift

@@ -53,7 +53,7 @@ class MVHomeController: MVBaseController {
     // 标签分类
     lazy var categoryCollectionView: UICollectionView = {
         let flowLayout = UICollectionViewFlowLayout()
-        flowLayout.sectionInset = UIEdgeInsets.zero
+        flowLayout.sectionInset = UIEdgeInsets.init(top: 0, left: 11, bottom: 0, right: 11)
         flowLayout.minimumLineSpacing = 0
         flowLayout.minimumInteritemSpacing = 10
         flowLayout.scrollDirection = .horizontal
@@ -231,7 +231,7 @@ class MVHomeController: MVBaseController {
         categoryCollectionView.snp.remakeConstraints { make in
             make.width.equalTo(cScreenWidth)
             make.height.equalTo(35)
-            make.left.equalToSuperview().offset(11)
+            make.left.equalToSuperview().offset(0)
             make.top.equalToSuperview().offset(cDevice_iPhoneStatusBarHei)
         }
     }
@@ -387,21 +387,25 @@ extension MVHomeController: MVBannerDataSource, MVBannerDelegate {
                 cell?.pauseView.isHidden = true
                 PQSingletoVideoPlayer.shared.configPlyer(videoData: self.mAllVideos[page], controllerView: cell!.converView)
 
-                let hotVides = self.mVideos.first(where: { (items) -> Bool in
+                let hotVideoIndex = self.mVideos.firstIndex(where: { (items) -> Bool in
                     items.categoryName == self.mAllVideos[page].categoryName
                 })
+                
+                BFLog(message: "播放的视频分类为:\(String(describing: self.mVideos[hotVideoIndex ?? 0].categoryName)) page is :\(page)")
+                //设置选中状态
                 for hot in self.mVideos {
                     hot.isSelected = false
                 }
+                self.mVideos[hotVideoIndex ?? 0].isSelected = true
 
-                self.mVideos[(hotVides?.categoryId ?? 0) - 1].isSelected = true
                 self.categoryCollectionView.reloadData()
+                self.categoryCollectionView.scrollToItem(at: IndexPath(row: hotVideoIndex ?? 0, section: 0), at:  .centeredHorizontally, animated: true)
 
                 self.lastBnnerSelectIndex = IndexPath(row: page, section: 0)
  
                 
             }else{
-                BFLog(message: "播放不成功: cell:\(cell) mVideos:\(self.mVideos.count) showProtocal: is \(showProtocal)")
+                BFLog(message: "播放不成功: cell:\(String(describing: cell)) mVideos:\(self.mVideos.count) showProtocal: is \(String(describing: showProtocal))")
             }
         }
     }