去掉打印,然后就是修复横屏后player bg的高度错误

This commit is contained in:
bluesea 2024-04-30 16:31:28 +08:00
parent 9810af4c01
commit 40ff5ead6e
2 changed files with 13 additions and 11 deletions

View File

@ -90,7 +90,7 @@ class ZZHCustomPlayer: UIView {
self.playBtn.snp.makeConstraints { make in
make.centerX.centerY.equalToSuperview()
make.width.height.equalTo(80)
make.width.height.equalTo(40)
}
return bgView
}()
@ -146,6 +146,7 @@ class ZZHCustomPlayer: UIView {
let playerWidth = KScreenWidth
playerLayerBgView = UIView()
playerLayerBgView?.backgroundColor = .clear
self.addSubview(playerLayerBgView!)
playerLayerBgView!.snp.makeConstraints { make in
make.left.right.equalToSuperview()
@ -162,6 +163,8 @@ class ZZHCustomPlayer: UIView {
})
avPlayerLayer = AVPlayerLayer(player: avPlayer)
// avPlayerLayer?.backgroundColor = UIColor.brown.cgColor
avPlayerLayer?.frame = CGRect(x: 0, y: 0, width: Int(playerWidth), height: playerHeight)
avPlayerLayer?.videoGravity = .resizeAspect
playerLayerBgView!.layer.addSublayer(avPlayerLayer!)
@ -210,7 +213,6 @@ class ZZHCustomPlayer: UIView {
make.left.equalTo(timeSlider!.snp.right).offset(24)
}
}
func updateEDBtnHeight() {
@ -235,7 +237,7 @@ class ZZHCustomPlayer: UIView {
timeSlider?.isHidden = false
edBtn?.isHidden = false
playerLayerBgView?.snp.updateConstraints { make in
make.height.equalTo(KScreenWidth)
make.height.equalTo(playerHeight)
}
self.layoutIfNeeded()
avPlayerLayer?.frame = CGRect(x: 0, y: 0, width: Int(KScreenWidth), height: playerHeight)

View File

@ -262,12 +262,12 @@ class PlayByTransferConvertor {
//
let x_offset = CGFloat(abs(ed) * edS) //x
let imageWidth = left.size.width*0.5 - x_offset
print("imageWidth:\(imageWidth) ,left.size.width*0.5:\(left.size.width*0.5) ")
// print("imageWidth:\(imageWidth) ,left.size.width*0.5:\(left.size.width*0.5) ")
let imageHeight = left.size.height
let (ed_left,last_left_size) = getImgWithED(image: n_left, drawImgWidth: imageWidth,drawSize: n_left_size)
let (ed_right,last_right_size) = getImgWithED(image: n_right, drawImgWidth: imageWidth,drawSize: n_right_size)
print("n_left_size:\(n_left_size)\nlast_left_size\(last_left_size)")
print("n_right_size:\(n_right_size)\nlast_right_size\(last_right_size)")
// print("n_left_size:\(n_left_size)\nlast_left_size\(last_left_size)")
// print("n_right_size:\(n_right_size)\nlast_right_size\(last_right_size)")
// testImageUi(image: ed_left)
let newImageSize = left.size
UIGraphicsBeginImageContextWithOptions(newImageSize, false, 1)
@ -276,12 +276,12 @@ class PlayByTransferConvertor {
ed_left.draw(in: CGRect(x:0, y:(imageHeight - last_left_size.height) * 0.5, width:last_left_size.width, height:last_left_size.height))
ed_right.draw(in: CGRect(x:newImageSize.width - last_right_size.width, y:(imageHeight - last_right_size.height) * 0.5, width:last_right_size.width, height:last_right_size.height))
print("ed>>>>> 0....")
// print("ed>>>>> 0....")
}
else if (ed < 0) {
ed_left.draw(in: CGRect(x:newImageSize.width*0.5 - last_left_size.width, y:(imageHeight - n_left_size.height) * 0.5, width:last_left_size.width, height:last_left_size.height))
ed_right.draw(in: CGRect(x:newImageSize.width*0.5, y:(imageHeight - n_right_size.height) * 0.5, width:last_right_size.width, height:last_right_size.height))
print("ed < 0....")
// print("ed < 0....")
}
else {//
let leftRect = CGRect(x:(imageWidth - n_left_size.width) * 0.5, y:(imageHeight - n_left_size.height) * 0.5 , width:n_left_size.width, height:n_left_size.height)
@ -290,7 +290,7 @@ class PlayByTransferConvertor {
let rightRect = CGRect(x:imageWidth + (imageWidth - n_right_size.width) * 0.5 , y:(imageHeight - n_right_size.height) * 0.5, width:n_right_size.width, height:n_right_size.height)
ed_right.draw(in:rightRect )
print("newImageSize:\(newImageSize) \nimageWidth:\(imageWidth) \ned_left.size:\(ed_left.size) \nleftRect:\(leftRect) \nrightRect:\(rightRect)")
// print("newImageSize:\(newImageSize) \nimageWidth:\(imageWidth) \ned_left.size:\(ed_left.size) \nleftRect:\(leftRect) \nrightRect:\(rightRect)")
}
@ -335,10 +335,10 @@ class PlayByTransferConvertor {
func getImgWithED(image:UIImage,drawImgWidth:CGFloat,drawSize:CGSize) -> (UIImage,CGSize) {
if drawSize.width <= drawImgWidth {
print("瞳距返回,不用处理")
// print(",")
return (image,drawSize)
}
print("瞳距要处理")
// print("")
// let s = drawSize.height / image.size.height
let newImageWidth = drawImgWidth * image.size.height / drawSize.height
let dRect = CGRectMake((image.size.width - newImageWidth) * 0.5, 0, newImageWidth, image.size.height)