Commit b386d389 authored by Alex朱枝文's avatar Alex朱枝文

直播ui问题修复

parent 1bdabf3b
...@@ -71,13 +71,13 @@ class YHLiveStateViewController: YHBaseViewController { ...@@ -71,13 +71,13 @@ class YHLiveStateViewController: YHBaseViewController {
make.edges.equalToSuperview() make.edges.equalToSuperview()
} }
blurEffect = { blurEffect = {
return UIBlurEffect(style: .dark) return UIBlurEffect(style: .light)
}() }()
blurView = { blurView = {
let view = UIVisualEffectView(effect: blurEffect) let view = UIVisualEffectView(effect: blurEffect)
view.frame = view.bounds view.frame = view.bounds
view.alpha = 0.5 view.alpha = 0.6
return view return view
}() }()
view.addSubview(blurView) view.addSubview(blurView)
......
...@@ -27,6 +27,12 @@ class YHVODPlayerViewController: YHBasePlayerViewController { ...@@ -27,6 +27,12 @@ class YHVODPlayerViewController: YHBasePlayerViewController {
return imageView return imageView
}() }()
private lazy var centerPlayIcon: UIImageView = {
let imageView = UIImageView(image: UIImage(named: "live_center_play"))
imageView.isHidden = true
return imageView
}()
private var isFirstAppear = true private var isFirstAppear = true
// MARK: - Initialization // MARK: - Initialization
...@@ -71,6 +77,7 @@ class YHVODPlayerViewController: YHBasePlayerViewController { ...@@ -71,6 +77,7 @@ class YHVODPlayerViewController: YHBasePlayerViewController {
player?.resume() player?.resume()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25, execute: { DispatchQueue.main.asyncAfter(deadline: .now() + 0.25, execute: {
self.progressControl.setPlaying(self.player?.getPlayState() == .playing) self.progressControl.setPlaying(self.player?.getPlayState() == .playing)
self.centerPlayIcon.isHidden = self.player?.getPlayState() == .playing
}) })
} }
} else { } else {
...@@ -101,12 +108,16 @@ class YHVODPlayerViewController: YHBasePlayerViewController { ...@@ -101,12 +108,16 @@ class YHVODPlayerViewController: YHBasePlayerViewController {
bottomImageView.snp.makeConstraints { make in bottomImageView.snp.makeConstraints { make in
make.edges.equalToSuperview() make.edges.equalToSuperview()
} }
containerView.addSubview(progressControl) containerView.addSubview(progressControl)
containerView.addSubview(centerPlayIcon)
progressControl.snp.makeConstraints { make in progressControl.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview() make.left.right.bottom.equalToSuperview()
make.top.equalTo(view.safeAreaLayoutGuide.snp.bottom).offset(-102) make.top.equalTo(view.safeAreaLayoutGuide.snp.bottom).offset(-102)
} }
centerPlayIcon.snp.makeConstraints { make in
make.centerY.centerX.equalToSuperview()
make.height.width.equalTo(62)
}
topBarView.closeButtonClickEvent = { [weak self] in topBarView.closeButtonClickEvent = { [weak self] in
self?.closeLive() self?.closeLive()
...@@ -123,6 +134,7 @@ class YHVODPlayerViewController: YHBasePlayerViewController { ...@@ -123,6 +134,7 @@ class YHVODPlayerViewController: YHBasePlayerViewController {
let needHideZoom = true //playbackInfo?.needHideZoomButton == true let needHideZoom = true //playbackInfo?.needHideZoomButton == true
topBarView.hideZoomButton(needHideZoom) topBarView.hideZoomButton(needHideZoom)
progressControl.setPlaying(player?.getPlayState() == .playing) progressControl.setPlaying(player?.getPlayState() == .playing)
centerPlayIcon.isHidden = player?.getPlayState() == .playing
} }
private func setupGestures() { private func setupGestures() {
...@@ -344,11 +356,14 @@ extension YHVODPlayerViewController: YHPlayerDelegate { ...@@ -344,11 +356,14 @@ extension YHVODPlayerViewController: YHPlayerDelegate {
case .playing: case .playing:
self.progressControl.setPlaying(true) self.progressControl.setPlaying(true)
printLog("####$$$.playing: \(player.getDuration())") printLog("####$$$.playing: \(player.getDuration())")
self.centerPlayIcon.isHidden = true
case .paused, .stopped: case .paused, .stopped:
printLog("####$$$.paused, .stopped") printLog("####$$$.paused, .stopped")
self.progressControl.setPlaying(false) self.progressControl.setPlaying(false)
self.centerPlayIcon.isHidden = false
case .failed: case .failed:
self.showAlert(message: "播放失败,错误原因:\(reason.rawValue)") //self.showAlert(message: "播放失败,错误原因:\(reason.rawValue)")
self.centerPlayIcon.isHidden = false
default: default:
break break
} }
......
...@@ -492,6 +492,49 @@ class YHFloatingWindow: NSObject { ...@@ -492,6 +492,49 @@ class YHFloatingWindow: NSObject {
return CGSize(width: width, height: height) return CGSize(width: width, height: height)
} }
// private func adjustedPosition(for center: CGPoint) -> CGPoint {
// guard let superview = containerView.superview else { return center }
//
// var adjustedCenter = center
// let halfWidth = containerView.bounds.width / 2
// let halfHeight = containerView.bounds.height / 2
//
// let safeAreaInsets: UIEdgeInsets
// if #available(iOS 11.0, *) {
// safeAreaInsets = superview.safeAreaInsets
// } else {
// safeAreaInsets = .zero
// }
//
// let topLimit = safeAreaInsets.top + halfHeight
// let bottomLimit = superview.bounds.height - safeAreaInsets.bottom - halfHeight
//
// adjustedCenter.x = min(max(halfWidth, adjustedCenter.x),
// superview.bounds.width - halfWidth)
// adjustedCenter.y = min(max(topLimit, adjustedCenter.y),
// bottomLimit)
//
// return adjustedCenter
// }
//
// private func handlePanEndedWithVelocity(_ velocity: CGPoint) {
// let magnitude = sqrt((velocity.x * velocity.x) + (velocity.y * velocity.y))
// let slideMultiplier = magnitude / 200
// let slideFactor = 0.1 * slideMultiplier
//
// var finalCenter = CGPoint(
// x: containerView.center.x + (velocity.x * slideFactor),
// y: containerView.center.y + (velocity.y * slideFactor)
// )
//
// finalCenter = adjustedPosition(for: finalCenter)
//
// UIView.animate(withDuration: 0.3) {
// self.containerView.center = finalCenter
// self.delegate?.floatingWindow(self, didChangePosition: finalCenter)
// }
// }
private func adjustedPosition(for center: CGPoint) -> CGPoint { private func adjustedPosition(for center: CGPoint) -> CGPoint {
guard let superview = containerView.superview else { return center } guard let superview = containerView.superview else { return center }
...@@ -506,13 +549,20 @@ class YHFloatingWindow: NSObject { ...@@ -506,13 +549,20 @@ class YHFloatingWindow: NSObject {
safeAreaInsets = .zero safeAreaInsets = .zero
} }
let topLimit = safeAreaInsets.top + halfHeight // 设置固定的边距
let bottomLimit = superview.bounds.height - safeAreaInsets.bottom - halfHeight let topMargin: CGFloat = 86 // 距离顶部statusbar 86
let bottomMargin: CGFloat = 86 // 距离底部安全区域 86
let horizontalMargin: CGFloat = 20 // 左右边距 20
// 计算活动范围的限制
let topLimit = max(safeAreaInsets.top + topMargin, halfHeight)
let bottomLimit = superview.bounds.height - max(safeAreaInsets.bottom + bottomMargin, halfHeight)
let leftLimit = horizontalMargin + halfWidth
let rightLimit = superview.bounds.width - horizontalMargin - halfWidth
adjustedCenter.x = min(max(halfWidth, adjustedCenter.x), // 应用限制
superview.bounds.width - halfWidth) adjustedCenter.x = min(max(leftLimit, adjustedCenter.x), rightLimit)
adjustedCenter.y = min(max(topLimit, adjustedCenter.y), adjustedCenter.y = min(max(topLimit, adjustedCenter.y), bottomLimit)
bottomLimit)
return adjustedCenter return adjustedCenter
} }
...@@ -529,9 +579,22 @@ class YHFloatingWindow: NSObject { ...@@ -529,9 +579,22 @@ class YHFloatingWindow: NSObject {
finalCenter = adjustedPosition(for: finalCenter) finalCenter = adjustedPosition(for: finalCenter)
// 确定最终吸附位置(左右两侧)
guard let superview = containerView.superview else { return }
let horizontalMargin: CGFloat = 20
let shouldMoveToRight = finalCenter.x > superview.bounds.width / 2
// 计算吸附后的 x 坐标
let finalX = shouldMoveToRight ?
(superview.bounds.width - horizontalMargin - containerView.bounds.width / 2) :
(horizontalMargin + containerView.bounds.width / 2)
// 保持 y 坐标不变,但确保在限制范围内
let finalY = finalCenter.y
UIView.animate(withDuration: 0.3) { UIView.animate(withDuration: 0.3) {
self.containerView.center = finalCenter self.containerView.center = CGPoint(x: finalX, y: finalY)
self.delegate?.floatingWindow(self, didChangePosition: finalCenter) self.delegate?.floatingWindow(self, didChangePosition: CGPoint(x: finalX, y: finalY))
} }
} }
} }
......
...@@ -70,7 +70,7 @@ class YHLiveMessageCell: UITableViewCell { ...@@ -70,7 +70,7 @@ class YHLiveMessageCell: UITableViewCell {
func configureTipsMessage(_ tips: String) { func configureTipsMessage(_ tips: String) {
let tipsIcon = ASAttributedString.init(.image(UIImage(named: "live_msg_tips_icon") ?? UIImage(), .custom(.offset(CGPoint(x: 0, y: -4.0)), size: .init(width: 32, height: 18)))) let tipsIcon = ASAttributedString.init(.image(UIImage(named: "live_msg_tips_icon") ?? UIImage(), .custom(.offset(CGPoint(x: 0, y: -4.0)), size: .init(width: 32, height: 18))))
let contentAtt = (tipsIcon + ASAttributedString(string: tips, .foreground(UIColor.white), .font(UIFont.PFSC_R(ofSize: 13)))) let contentAtt = (tipsIcon + ASAttributedString(string: " \(tips)", .foreground(UIColor.white), .font(UIFont.PFSC_R(ofSize: 13))))
contentLabel.attributed.text = contentAtt contentLabel.attributed.text = contentAtt
} }
} }
...@@ -17,7 +17,7 @@ class YHLiveShopView: UIView { ...@@ -17,7 +17,7 @@ class YHLiveShopView: UIView {
var titleLabel: UILabel! var titleLabel: UILabel!
var subTitleLabel: UILabel! var subTitleLabel: UILabel!
var closeButton: UIButton! var closeButton: UIButton!
var lineView: UIView! //var lineView: UIView!
var tableView: UITableView! var tableView: UITableView!
var dataSource: [YHLiveGoodsItem] = [] { var dataSource: [YHLiveGoodsItem] = [] {
didSet { didSet {
...@@ -33,7 +33,7 @@ class YHLiveShopView: UIView { ...@@ -33,7 +33,7 @@ class YHLiveShopView: UIView {
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
backgroundColor = UIColor(white: 0.5, alpha: 0.1) //backgroundColor = UIColor(white: 0.5, alpha: 0.1)
let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap)) let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap))
tap.delegate = self tap.delegate = self
addGestureRecognizer(tap) addGestureRecognizer(tap)
...@@ -53,8 +53,9 @@ class YHLiveShopView: UIView { ...@@ -53,8 +53,9 @@ class YHLiveShopView: UIView {
}() }()
addSubview(centerView) addSubview(centerView)
centerView.snp.makeConstraints { make in centerView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(295)
make.left.right.bottom.equalToSuperview() make.left.right.bottom.equalToSuperview()
make.height.equalTo(518) // make.height.equalTo(518)
} }
let headImageView = { let headImageView = {
...@@ -99,18 +100,18 @@ class YHLiveShopView: UIView { ...@@ -99,18 +100,18 @@ class YHLiveShopView: UIView {
make.top.equalTo(16) make.top.equalTo(16)
} }
lineView = { // lineView = {
let view = UIView() // let view = UIView()
view.backgroundColor = UIColor.separatorColor // view.backgroundColor = UIColor.separatorColor
return view // return view
}() // }()
centerView.addSubview(lineView) // centerView.addSubview(lineView)
lineView.snp.makeConstraints { make in // lineView.snp.makeConstraints { make in
make.left.equalTo(18) // make.left.equalTo(18)
make.top.equalTo(52) // make.top.equalTo(52)
make.height.equalTo(1) // make.height.equalTo(1)
make.right.equalTo(-18) // make.right.equalTo(-18)
} // }
tableView = { tableView = {
let tableView = UITableView(frame: .zero, style: .grouped) let tableView = UITableView(frame: .zero, style: .grouped)
...@@ -223,6 +224,7 @@ class YHLiveShopViewCell: UITableViewCell { ...@@ -223,6 +224,7 @@ class YHLiveShopViewCell: UITableViewCell {
var subPriceLabel: UILabel! var subPriceLabel: UILabel!
var flagLabel: UILabel! var flagLabel: UILabel!
var buyButton: UIButton! var buyButton: UIButton!
var lineView: UIView!
//var addButton: UIButton! //var addButton: UIButton!
// var addEvent: (() -> Void)? // var addEvent: (() -> Void)?
...@@ -238,9 +240,9 @@ class YHLiveShopViewCell: UITableViewCell { ...@@ -238,9 +240,9 @@ class YHLiveShopViewCell: UITableViewCell {
titleLabel.text = dataSource.name titleLabel.text = dataSource.name
messageLabel.text = dataSource.description messageLabel.text = dataSource.description
let a: ASAttributedString = .init("¥", .font(UIFont.PFSC_R(ofSize: 14)),.foreground(UIColor.mainTextColor)) let a: ASAttributedString = .init("¥", .font(UIFont.PFSC_R(ofSize: 14)),.foreground(UIColor.mainTextColor))
let b: ASAttributedString = .init("\(dataSource.linePrice)", .font(UIFont.PFSC_R(ofSize: 20)),.foreground(UIColor.mainTextColor)) let b: ASAttributedString = .init("\(dataSource.linePrice)", .font(UIFont(name: "DINAlternate-Bold", size: 20) ?? UIFont.PFSC_R(ofSize: 20)),.foreground(UIColor.mainTextColor))
priceLabel.attributed.text = a + b priceLabel.attributed.text = a + b
let c: ASAttributedString = .init("\(dataSource.price)", .font(UIFont.PFSC_R(ofSize: 14)),.foreground(UIColor(hex:0x8993a2)), .strikethrough(.single)) let c: ASAttributedString = .init("¥\(dataSource.price)", .font(UIFont.PFSC_R(ofSize: 14)),.foreground(UIColor(hex:0x8993a2)), .strikethrough(.single))
subPriceLabel.attributed.text = c subPriceLabel.attributed.text = c
flagLabel.text = "\(dataSource.flag)" flagLabel.text = "\(dataSource.flag)"
subPriceLabel.isHidden = dataSource.linePrice == dataSource.price subPriceLabel.isHidden = dataSource.linePrice == dataSource.price
...@@ -268,7 +270,21 @@ class YHLiveShopViewCell: UITableViewCell { ...@@ -268,7 +270,21 @@ class YHLiveShopViewCell: UITableViewCell {
} }
func setupUI() { func setupUI() {
self.backgroundColor = .white //self.backgroundColor = .white
lineView = {
let view = UIView()
view.backgroundColor = UIColor.separatorColor
return view
}()
contentView.addSubview(lineView)
lineView.snp.makeConstraints { make in
make.left.equalTo(18)
make.top.equalTo(0)
make.height.equalTo(0.5)
make.right.equalTo(-18)
}
centerImageView = { centerImageView = {
let imageView = UIImageView() let imageView = UIImageView()
imageView.image = UIImage(named: "global_default_image") imageView.image = UIImage(named: "global_default_image")
...@@ -360,6 +376,8 @@ class YHLiveShopViewCell: UITableViewCell { ...@@ -360,6 +376,8 @@ class YHLiveShopViewCell: UITableViewCell {
button.setTitle("去抢购", for: .normal) button.setTitle("去抢购", for: .normal)
button.setTitleColor(UIColor.white, for: .normal) button.setTitleColor(UIColor.white, for: .normal)
button.addTarget(self, action: #selector(buy), for: .touchUpInside) button.addTarget(self, action: #selector(buy), for: .touchUpInside)
button.layer.cornerRadius = 2
button.clipsToBounds = true
return button return button
}() }()
contentView.addSubview(buyButton) contentView.addSubview(buyButton)
......
...@@ -43,7 +43,7 @@ class YHPlayerTopBarView: UIView { ...@@ -43,7 +43,7 @@ class YHPlayerTopBarView: UIView {
let label = UILabel() let label = UILabel()
label.text = "-" label.text = "-"
label.textColor = .white.withAlphaComponent(0.7) label.textColor = .white.withAlphaComponent(0.7)
label.font = .PFSC_R(ofSize: 10) label.font = .PFSC_R(ofSize: 12)
return label return label
}() }()
......
...@@ -48,7 +48,7 @@ class YHVideoProgressControl: UIView { ...@@ -48,7 +48,7 @@ class YHVideoProgressControl: UIView {
private lazy var currentTimeLabel: UILabel = { private lazy var currentTimeLabel: UILabel = {
let label = UILabel() let label = UILabel()
label.textColor = .white label.textColor = .white
label.font = .PFSC_R(ofSize: 12) label.font = .PFSC_M(ofSize: 12)
return label return label
}() }()
...@@ -140,7 +140,7 @@ class YHVideoProgressControl: UIView { ...@@ -140,7 +140,7 @@ class YHVideoProgressControl: UIView {
segmentCollection.snp.makeConstraints { make in segmentCollection.snp.makeConstraints { make in
make.top.equalToSuperview().offset(16) make.top.equalToSuperview().offset(16)
make.left.equalToSuperview().offset(16) make.left.equalToSuperview().offset(16)
make.height.equalTo(20) make.height.equalTo(22)
make.right.equalToSuperview().offset(-4) make.right.equalToSuperview().offset(-4)
} }
progressSlider.snp.makeConstraints { make in progressSlider.snp.makeConstraints { make in
...@@ -306,9 +306,9 @@ extension YHVideoProgressControl: UICollectionViewDataSource, UICollectionViewDe ...@@ -306,9 +306,9 @@ extension YHVideoProgressControl: UICollectionViewDataSource, UICollectionViewDe
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let text = segments[indexPath.item] let text = segments[indexPath.item]
let attr = NSAttributedString(string: text, attributes: [.font: UIFont.systemFont(ofSize: 8)]) let attr = NSAttributedString(string: text, attributes: [.font: UIFont.systemFont(ofSize: 10)])
let width = attr.yh_width(containerHeight: 20) + 8 let width = attr.yh_width(containerHeight: 22) + 8
return CGSize(width: width, height: 20) return CGSize(width: width, height: 22)
} }
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
...@@ -324,7 +324,7 @@ class SegmentCell: UICollectionViewCell { ...@@ -324,7 +324,7 @@ class SegmentCell: UICollectionViewCell {
private let titleLabel: UILabel = { private let titleLabel: UILabel = {
let label = UILabel() let label = UILabel()
label.textColor = .white label.textColor = .white
label.font = .systemFont(ofSize: 8) label.font = .systemFont(ofSize: 10)
label.textAlignment = .center label.textAlignment = .center
return label return label
}() }()
......
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "live_center_play@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "live_center_play@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
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