Commit 3eda72be authored by Alex朱枝文's avatar Alex朱枝文

优化新消息到来的隐藏效果、优化从后台回来IM状态断开

parent 5f72409f
...@@ -904,6 +904,9 @@ extension YHLivePlayerViewController { ...@@ -904,6 +904,9 @@ extension YHLivePlayerViewController {
@objc private func handleAppWillEnterForeground() { @objc private func handleAppWillEnterForeground() {
if YHLoginManager.shared.isLogin() { if YHLoginManager.shared.isLogin() {
joinLiveRoom(id: liveId, callback: { _, _ in }) joinLiveRoom(id: liveId, callback: { _, _ in })
if let roomId = roomId {
setupChatRoom(roomId: roomId)
}
} }
} }
/* /*
...@@ -976,7 +979,9 @@ extension YHLivePlayerViewController { ...@@ -976,7 +979,9 @@ extension YHLivePlayerViewController {
if #available(iOS 16.0, *) { if #available(iOS 16.0, *) {
windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: orientationMask)) windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: orientationMask))
} else { } else {
// let orientation: UIInterfaceOrientation = orientationMask == .portrait ? .portrait : .landscapeRight
// UIDevice.current.setValue(orientation.rawValue, forKey: "orientation")
// UIViewController.attemptRotationToDeviceOrientation()
} }
} }
...@@ -987,6 +992,9 @@ extension YHLivePlayerViewController { ...@@ -987,6 +992,9 @@ extension YHLivePlayerViewController {
if #available(iOS 16.0, *) { if #available(iOS 16.0, *) {
windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: orientationMask)) windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: orientationMask))
} else { } else {
// let orientation: UIInterfaceOrientation = .portrait
// UIDevice.current.setValue(orientation.rawValue, forKey: "orientation")
// UIViewController.attemptRotationToDeviceOrientation()
} }
bottomInputBar.isHidden = false bottomInputBar.isHidden = false
messageListView.isHidden = false messageListView.isHidden = false
...@@ -1002,6 +1010,9 @@ extension YHLivePlayerViewController { ...@@ -1002,6 +1010,9 @@ extension YHLivePlayerViewController {
if #available(iOS 16.0, *) { if #available(iOS 16.0, *) {
windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: orientationMask)) windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: orientationMask))
} else { } else {
// let orientation: UIInterfaceOrientation = .landscapeRight
// UIDevice.current.setValue(orientation.rawValue, forKey: "orientation")
// UIViewController.attemptRotationToDeviceOrientation()
} }
bottomInputBar.isHidden = true bottomInputBar.isHidden = true
messageListView.isHidden = true messageListView.isHidden = true
......
...@@ -47,6 +47,9 @@ class YHLiveMessageListView: UIView { ...@@ -47,6 +47,9 @@ class YHLiveMessageListView: UIView {
make.top.equalToSuperview() make.top.equalToSuperview()
make.left.bottom.right.equalToSuperview() make.left.bottom.right.equalToSuperview()
} }
// 添加 KVO
tableView.addObserver(self, forKeyPath: "contentSize", options: .new, context: nil)
} }
// MARK: - Public Methods // MARK: - Public Methods
...@@ -63,12 +66,20 @@ class YHLiveMessageListView: UIView { ...@@ -63,12 +66,20 @@ class YHLiveMessageListView: UIView {
messages.removeAll() messages.removeAll()
tableView.reloadData() tableView.reloadData()
} }
}
deinit {
// MARK: - UITableViewDelegate & UITableViewDataSource // 移除 KVO
tableView.removeObserver(self, forKeyPath: "contentSize")
extension YHLiveMessageListView: UITableViewDelegate, UITableViewDataSource { }
func scrollViewDidScroll(_ scrollView: UIScrollView) {
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "contentSize" {
fadeCells()
}
}
private func fadeCells() {
// 内容大小变化
let fadeRange: CGFloat = 50 let fadeRange: CGFloat = 50
tableView.visibleCells.forEach { cell in tableView.visibleCells.forEach { cell in
...@@ -76,7 +87,7 @@ extension YHLiveMessageListView: UITableViewDelegate, UITableViewDataSource { ...@@ -76,7 +87,7 @@ extension YHLiveMessageListView: UITableViewDelegate, UITableViewDataSource {
let cellRect = tableView.rectForRow(at: indexPath) let cellRect = tableView.rectForRow(at: indexPath)
// 因为视图是倒置的,所以我们需要用 tableView 的高度来计算正确的位置 // 因为视图是倒置的,所以我们需要用 tableView 的高度来计算正确的位置
let cellPositionFromBottom = tableView.bounds.height - (cellRect.origin.y - scrollView.contentOffset.y) - cellRect.height let cellPositionFromBottom = tableView.bounds.height - (cellRect.origin.y - tableView.contentOffset.y) - cellRect.height
if cellPositionFromBottom >= 0 && cellPositionFromBottom <= fadeRange { if cellPositionFromBottom >= 0 && cellPositionFromBottom <= fadeRange {
let progress = cellPositionFromBottom / fadeRange let progress = cellPositionFromBottom / fadeRange
...@@ -88,6 +99,14 @@ extension YHLiveMessageListView: UITableViewDelegate, UITableViewDataSource { ...@@ -88,6 +99,14 @@ extension YHLiveMessageListView: UITableViewDelegate, UITableViewDataSource {
} }
} }
} }
}
// MARK: - UITableViewDelegate & UITableViewDataSource
extension YHLiveMessageListView: UITableViewDelegate, UITableViewDataSource {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
fadeCells()
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension return UITableView.automaticDimension
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment