Selaa lähdekoodia

feat: 直播间公屏底部增加渐变遮罩

陈文艺 1 päivä sitten
vanhempi
sitoutus
a651cb14b9
1 muutettua tiedostoa jossa 28 lisäystä ja 4 poistoa
  1. 28 4
      Lanu/Views/Room/Message/LNRoomMessageView.swift

+ 28 - 4
Lanu/Views/Room/Message/LNRoomMessageView.swift

@@ -73,13 +73,14 @@ extension LNRoomMessageView: UITableViewDataSource {
 
 extension LNRoomMessageView {
     private func setupViews() {
-        tableView.backgroundColor = .clear
+        tableView.dataSource = self
+        tableView.allowsSelection = false
         tableView.separatorStyle = .none
-        tableView.showsVerticalScrollIndicator = false
+        tableView.backgroundColor = .clear
         tableView.alwaysBounceVertical = true
-        tableView.allowsSelection = false
+        tableView.showsVerticalScrollIndicator = false
         tableView.contentInsetAdjustmentBehavior = .never
-        tableView.dataSource = self
+        tableView.contentInset = .init(top: 0, left: 0, bottom: 16, right: 0)
         tableView.register(LNRoomChatMessageCell.self, forCellReuseIdentifier: LNRoomChatMessageCell.className)
         tableView.register(LNRoomGiftMessageCell.self, forCellReuseIdentifier: LNRoomGiftMessageCell.className)
         tableView.register(LNRoomSystemMessageCell.self, forCellReuseIdentifier: LNRoomSystemMessageCell.className)
@@ -89,6 +90,29 @@ extension LNRoomMessageView {
         tableView.snp.makeConstraints { make in
             make.edges.equalToSuperview()
         }
+        
+        let bottomGradientView = UIView()
+        bottomGradientView.isUserInteractionEnabled = false
+        addSubview(bottomGradientView)
+        bottomGradientView.snp.makeConstraints { make in
+            make.horizontalEdges.equalToSuperview()
+            make.bottom.equalToSuperview()
+            make.height.equalTo(44)
+        }
+        
+        let gradientLayer = CAGradientLayer()
+        gradientLayer.colors = [
+            UIColor(hex: "#010B2300").cgColor,
+            UIColor(hex: "#010B23").cgColor
+        ]
+        gradientLayer.startPoint = .zero
+        gradientLayer.endPoint = .init(x: 0, y: 1)
+        bottomGradientView.layer.addSublayer(gradientLayer)
+        bottomGradientView.publisher(for: \.bounds).removeDuplicates().sink
+        { [weak gradientLayer] newValue in
+            guard let gradientLayer else { return }
+            gradientLayer.frame = newValue
+        }.store(in: &cancellables)
     }
 }