Przeglądaj źródła

播放视频高度

Chris 5 lat temu
rodzic
commit
adfe0f5366

+ 32 - 7
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityVideoContent/View/CommunityVideoCoverCollectionCell.swift

@@ -722,7 +722,6 @@ class CommunityVideoCoverCollectionCell: UICollectionViewCell {
             
             beanLabel.text = "\(self.videoItemMdl?.willCollectBean ?? 0)彩虹豆待收获"
             
-            
             avatarButton.kf.setImage(with: kURLImage(name: self.videoItemMdl?.avatar ?? ""), for: .normal, placeholder: kImage(name: "default_avatar"))
             personLabel.text = self.videoItemMdl?.username
             
@@ -764,7 +763,7 @@ class CommunityVideoCoverCollectionCell: UICollectionViewCell {
             topicView.topicArray = self.videoItemMdl?.topic
             topicView.reloadData()
             
-//            contentLabel.text = self.videoItemMdl?.content
+            self.remakePlayViewConstrains()
             
             self.addSeeMoreButton(contentLabel, textStr: self.videoItemMdl?.content)
             
@@ -774,10 +773,39 @@ class CommunityVideoCoverCollectionCell: UICollectionViewCell {
         }
     }
     
-    func remakeBottomConstrains() {
+    // 根据返回url中包含的size,重新计算约束播放视图高度
+    func remakePlayViewConstrains() {
+        let imgUrlStr: String = self.videoItemMdl?.img ?? ""
+        
+        var leadingIdx = imgUrlStr.firstIndex(of: "*") ?? imgUrlStr.endIndex
+        leadingIdx = imgUrlStr.index(leadingIdx, offsetBy: 1)
+        let cutLeadUrl = imgUrlStr.suffix(from: leadingIdx)
+        
+        let trailingIdx = cutLeadUrl.firstIndex(of: ".") ?? cutLeadUrl.endIndex
+        let sizeStr = cutLeadUrl.prefix(upTo: trailingIdx)
         
+        let arraySubstrings: [Substring] = sizeStr.split(separator: "_")
+        let widthStr  = arraySubstrings[0]
+        let heightStr = arraySubstrings[1]
+        
+        let doubleWidth = Double(widthStr)
+        let fWidth = CGFloat(doubleWidth ?? 0)
+        
+        let doubleHeight = Double(heightStr)
+        let fHeight = CGFloat(doubleHeight ?? 0)
+        
+        let vHeight = kScreenWidth/fWidth*fHeight                
+        self.videoPlayView.snp.remakeConstraints { (make) in
+            make.left.right.equalToSuperview()
+            make.centerY.equalToSuperview()
+            make.height.equalTo(vHeight)
+        }
+    }
+    
+    func remakeBottomConstrains() {
         let size: CGSize = contentLabel.sizeThatFits(CGSize(width: kScreenWidth-28, height: CGFloat(MAXFLOAT)))
-        print("------size == \(size)")
+        contentScrollView.contentSize = CGSize.init(width: kScreenWidth-28.0, height: size.height)
+        print("------bottomSize == \(size)")
         
         if size.height > 40 {
             // 超过2行
@@ -799,9 +827,6 @@ class CommunityVideoCoverCollectionCell: UICollectionViewCell {
             }
         }
         
-        
-        
-        
     }
     
 }