Skip to content

Commit

Permalink
use leadingAnchor and trailingAnchor
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Aug 18, 2021
1 parent ac7d91c commit bcb99de
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 82 deletions.
4 changes: 2 additions & 2 deletions Demo/demo-iOS/demo-iOS/AudioViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class AudioViewController: UIViewController, DetailProtocol {
playerView.backgroundColor = UIColor.white
playerView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
playerView.leftAnchor.constraint(equalTo: view.leftAnchor),
playerView.rightAnchor.constraint(equalTo: view.rightAnchor),
playerView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
playerView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
playerView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
])
view.layoutIfNeeded()
Expand Down
8 changes: 4 additions & 4 deletions Demo/demo-iOS/demo-iOS/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ class DetailViewController: UIViewController, DetailProtocol {
#if os(iOS)
NSLayoutConstraint.activate([
playerView.topAnchor.constraint(equalTo: view.readableContentGuide.topAnchor),
playerView.leftAnchor.constraint(equalTo: view.leftAnchor),
playerView.rightAnchor.constraint(equalTo: view.rightAnchor),
playerView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
playerView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
playerView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
#else
NSLayoutConstraint.activate([
playerView.topAnchor.constraint(equalTo: view.topAnchor),
playerView.leftAnchor.constraint(equalTo: view.leftAnchor),
playerView.rightAnchor.constraint(equalTo: view.rightAnchor),
playerView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
playerView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
playerView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
#endif
Expand Down
8 changes: 4 additions & 4 deletions Demo/demo-iOS/demo-iOS/MasterViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class TableViewCell: UITableViewCell {
nameLabel.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
nameLabel.topAnchor.constraint(equalTo: contentView.topAnchor),
nameLabel.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 10),
nameLabel.rightAnchor.constraint(equalTo: contentView.rightAnchor),
nameLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 10),
nameLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
nameLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
])
}
Expand All @@ -38,8 +38,8 @@ class MasterViewController: UIViewController, UITableViewDelegate, UITableViewDa
tableView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: view.topAnchor),
tableView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0),
tableView.rightAnchor.constraint(equalTo: view.rightAnchor),
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0),
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
tableView.delegate = self
Expand Down
4 changes: 2 additions & 2 deletions Demo/demo-macOS/demo-macOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class ViewController: NSViewController {
playerView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
playerView.topAnchor.constraint(equalTo: view.topAnchor),
playerView.leftAnchor.constraint(equalTo: view.leftAnchor),
playerView.rightAnchor.constraint(equalTo: view.rightAnchor),
playerView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
playerView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
playerView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
}
Expand Down
6 changes: 1 addition & 5 deletions Sources/KSPlayer/AVPlayer/PlayerDefines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ extension MediaPlayerProtocol {
if category == .playback || category == .playAndRecord {
return
}
if #available(iOS 11.0, tvOS 11.0, *) {
try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, policy: .longFormAudio)
} else {
try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
}
try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, policy: .longFormAudio)
try? AVAudioSession.sharedInstance().setActive(true)
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/KSPlayer/Audio/AudioPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ open class AudioPlayerView: PlayerView {
addSubview(toolBar)
toolBar.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
toolBar.leftAnchor.constraint(equalTo: leftAnchor, constant: 7),
toolBar.rightAnchor.constraint(equalTo: rightAnchor, constant: -12),
toolBar.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 7),
toolBar.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -12),
toolBar.topAnchor.constraint(equalTo: topAnchor),
toolBar.bottomAnchor.constraint(equalTo: bottomAnchor),
])
Expand Down
20 changes: 10 additions & 10 deletions Sources/KSPlayer/Basic/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,31 +160,31 @@ public extension UIView {
}

var safeTopAnchor: NSLayoutYAxisAnchor {
if #available(iOS 11.0, tvOS 11.0, macOS 11.0, *) {
if #available(macOS 11.0, *) {
return self.safeAreaLayoutGuide.topAnchor
} else {
return topAnchor
}
}

var safeLeftAnchor: NSLayoutXAxisAnchor {
if #available(iOS 11.0, tvOS 11.0, macOS 11.0, *) {
return self.safeAreaLayoutGuide.leftAnchor
var safeLeadingAnchor: NSLayoutXAxisAnchor {
if #available(macOS 11.0, *) {
return self.safeAreaLayoutGuide.leadingAnchor
} else {
return leftAnchor
return leadingAnchor
}
}

var safeRightAnchor: NSLayoutXAxisAnchor {
if #available(iOS 11.0, tvOS 11.0, macOS 11.0, *) {
return self.safeAreaLayoutGuide.rightAnchor
var safeTrailingAnchor: NSLayoutXAxisAnchor {
if #available(macOS 11.0, *) {
return self.safeAreaLayoutGuide.trailingAnchor
} else {
return rightAnchor
return trailingAnchor
}
}

var safeBottomAnchor: NSLayoutYAxisAnchor {
if #available(iOS 11.0, tvOS 11.0, macOS 11.0, *) {
if #available(macOS 11.0, *) {
return self.safeAreaLayoutGuide.bottomAnchor
} else {
return bottomAnchor
Expand Down
10 changes: 3 additions & 7 deletions Sources/KSPlayer/MEPlayer/HardwareDecode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension KSOptions {
func canHardwareDecode(codecpar: AVCodecParameters) -> Bool {
if codecpar.codec_id == AV_CODEC_ID_H264, hardwareDecodeH264 {
return true
} else if codecpar.codec_id == AV_CODEC_ID_HEVC, #available(iOS 11.0, tvOS 11.0, *), VTIsHardwareDecodeSupported(kCMVideoCodecType_HEVC), hardwareDecodeH265 {
} else if codecpar.codec_id == AV_CODEC_ID_HEVC, VTIsHardwareDecodeSupported(kCMVideoCodecType_HEVC), hardwareDecodeH265 {
return true
}
return false
Expand Down Expand Up @@ -258,17 +258,13 @@ extension AVColorTransferCharacteristic {
case AVCOL_TRC_SMPTE240M:
return kCVImageBufferTransferFunction_SMPTE_240M_1995
case AVCOL_TRC_SMPTE2084:
if #available(iOS 11.0, tvOS 11.0, *) {
return kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ
}
return kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ
case AVCOL_TRC_LINEAR:
if #available(iOS 12.0, tvOS 12.0, OSX 10.14, *) {
return kCVImageBufferTransferFunction_Linear
}
case AVCOL_TRC_ARIB_STD_B67:
if #available(iOS 11.0, tvOS 11.0, *) {
return kCVImageBufferTransferFunction_ITU_R_2100_HLG
}
return kCVImageBufferTransferFunction_ITU_R_2100_HLG
case AVCOL_TRC_GAMMA22, AVCOL_TRC_GAMMA28:
return kCVImageBufferTransferFunction_UseGamma
case AVCOL_TRC_BT2020_10, AVCOL_TRC_BT2020_12:
Expand Down
6 changes: 1 addition & 5 deletions Sources/KSPlayer/MEPlayer/Resample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,7 @@ class PixelBuffer: BufferProtocol {
}
var size = [Int]()
for i in 0 ..< planeCount {
if #available(iOS 11.0, tvOS 11.0, *) {
lineSize.append(bytesPerRow[i].alignment(value: MetalRender.device.minimumLinearTextureAlignment(for: formats[i])))
} else {
lineSize.append(bytesPerRow[i])
}
lineSize.append(bytesPerRow[i].alignment(value: MetalRender.device.minimumLinearTextureAlignment(for: formats[i])))
size.append(lineSize[i] * heights[i])
}
dataWrap = ObjectPool.share.object(class: MTLBufferWrap.self, key: "VideoData") { MTLBufferWrap(size: size) }
Expand Down
14 changes: 7 additions & 7 deletions Sources/KSPlayer/Video/BrightnessVolume.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ private final class SystemView: UIVisualEffectView {
titleLabel.widthAnchor.constraint(equalTo: widthAnchor),
titleLabel.centerXAnchor.constraint(equalTo: centerXAnchor),
titleLabel.heightAnchor.constraint(equalToConstant: 30),
longView.leftAnchor.constraint(equalTo: leftAnchor, constant: 13),
longView.rightAnchor.constraint(equalTo: rightAnchor, constant: -13),
longView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 13),
longView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -13),
longView.heightAnchor.constraint(equalToConstant: 7),
longView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -16),
stackView.leftAnchor.constraint(equalTo: longView.leftAnchor, constant: 1),
stackView.rightAnchor.constraint(equalTo: longView.rightAnchor, constant: -1),
stackView.leadingAnchor.constraint(equalTo: longView.leadingAnchor, constant: 1),
stackView.trailingAnchor.constraint(equalTo: longView.trailingAnchor, constant: -1),
stackView.topAnchor.constraint(equalTo: longView.topAnchor, constant: 1),
stackView.bottomAnchor.constraint(equalTo: longView.bottomAnchor, constant: -1),
])
Expand Down Expand Up @@ -184,8 +184,8 @@ private final class ProgressView: UIView {
progressView.heightAnchor.constraint(equalToConstant: 2),
progressView.centerXAnchor.constraint(equalTo: centerXAnchor),
progressView.topAnchor.constraint(equalTo: topAnchor, constant: 57),
imageView.leftAnchor.constraint(equalTo: leftAnchor),
imageView.rightAnchor.constraint(equalTo: rightAnchor),
imageView.leadingAnchor.constraint(equalTo: leadingAnchor),
imageView.trailingAnchor.constraint(equalTo: trailingAnchor),
imageView.bottomAnchor.constraint(equalTo: bottomAnchor),
])
}
Expand All @@ -212,7 +212,7 @@ extension ProgressView: BrightnessVolumeViewProtocol {
view.addSubview(self)
translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
rightAnchor.constraint(equalTo: view.safeRightAnchor, constant: -10),
trailingAnchor.constraint(equalTo: view.safeTrailingAnchor, constant: -10),
centerYAnchor.constraint(equalTo: view.centerYAnchor),
heightAnchor.constraint(equalToConstant: 150),
widthAnchor.constraint(equalToConstant: 24),
Expand Down
10 changes: 5 additions & 5 deletions Sources/KSPlayer/Video/IOSVideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ open class IOSVideoPlayerView: VideoPlayerView {
maskImageView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
maskImageView.topAnchor.constraint(equalTo: topAnchor),
maskImageView.leftAnchor.constraint(equalTo: leftAnchor),
maskImageView.leadingAnchor.constraint(equalTo: leadingAnchor),
maskImageView.bottomAnchor.constraint(equalTo: bottomAnchor),
maskImageView.rightAnchor.constraint(equalTo: rightAnchor),
maskImageView.trailingAnchor.constraint(equalTo: trailingAnchor),
backButton.widthAnchor.constraint(equalToConstant: 25),
lockButton.leftAnchor.constraint(equalTo: safeLeftAnchor, constant: 22),
lockButton.leadingAnchor.constraint(equalTo: safeLeadingAnchor, constant: 22),
lockButton.centerYAnchor.constraint(equalTo: centerYAnchor),
routeButton.widthAnchor.constraint(equalToConstant: 25),
landscapeButton.widthAnchor.constraint(equalToConstant: 30),
Expand Down Expand Up @@ -304,8 +304,8 @@ public class AirplayStatusView: UIView {
airplayicon.widthAnchor.constraint(equalToConstant: 100),
airplayicon.heightAnchor.constraint(equalToConstant: 100),
airplaymessage.bottomAnchor.constraint(equalTo: bottomAnchor),
airplaymessage.leftAnchor.constraint(equalTo: leftAnchor),
airplaymessage.rightAnchor.constraint(equalTo: rightAnchor),
airplaymessage.leadingAnchor.constraint(equalTo: leadingAnchor),
airplaymessage.trailingAnchor.constraint(equalTo: trailingAnchor),
airplaymessage.heightAnchor.constraint(equalToConstant: 15),
])
isHidden = true
Expand Down
10 changes: 5 additions & 5 deletions Sources/KSPlayer/Video/KSSubtitleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class KSSubtitleView: UIControl, SubtitleViewProtocol {
tableView.backgroundColor = UIColor(white: 0, alpha: 0.7)
addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false
tableViewRightConstraint = tableView.rightAnchor.constraint(equalTo: rightAnchor)
tableViewRightConstraint = tableView.trailingAnchor.constraint(equalTo: trailingAnchor)
#if canImport(UIKit)
#if !os(tvOS)
tableView.separatorColor = UIColor(white: 1, alpha: 0.15)
Expand Down Expand Up @@ -158,18 +158,18 @@ public class SrtListCell: UITableViewCell {
checkView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
titleLabel.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 20),
titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 20),
titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor),
titleLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor),
titleLabel.rightAnchor.constraint(equalTo: localIconView.leftAnchor, constant: -12),
titleLabel.trailingAnchor.constraint(equalTo: localIconView.leadingAnchor, constant: -12),
localIconViewWidth,
localIconView.heightAnchor.constraint(equalToConstant: 20),
localIconView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
localIconView.rightAnchor.constraint(equalTo: checkView.leftAnchor),
localIconView.trailingAnchor.constraint(equalTo: checkView.leadingAnchor),
checkView.widthAnchor.constraint(equalToConstant: 20),
checkView.heightAnchor.constraint(equalToConstant: 20),
checkView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
checkView.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: -15),
checkView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -15),
])
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/KSPlayer/Video/MacVideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class UIActivityIndicatorView: UIView {
loadingView.widthAnchor.constraint(equalTo: widthAnchor),
loadingView.heightAnchor.constraint(equalTo: heightAnchor),
imageView.bottomAnchor.constraint(equalTo: loadingView.bottomAnchor),
imageView.leftAnchor.constraint(equalTo: loadingView.leftAnchor),
imageView.leadingAnchor.constraint(equalTo: loadingView.leadingAnchor),
imageView.heightAnchor.constraint(equalTo: widthAnchor),
imageView.widthAnchor.constraint(equalTo: heightAnchor),
])
Expand Down
4 changes: 2 additions & 2 deletions Sources/KSPlayer/Video/SeekView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class SeekView: UIView {
seekToViewImage.translatesAutoresizingMaskIntoConstraints = false
seekToLabel.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
seekToViewImage.leftAnchor.constraint(equalTo: leftAnchor, constant: 15),
seekToViewImage.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 15),
seekToViewImage.centerYAnchor.constraint(equalTo: centerYAnchor),
seekToViewImage.widthAnchor.constraint(equalToConstant: 25),
seekToViewImage.heightAnchor.constraint(equalToConstant: 15),
seekToLabel.leftAnchor.constraint(equalTo: seekToViewImage.rightAnchor, constant: 10),
seekToLabel.leadingAnchor.constraint(equalTo: seekToViewImage.trailingAnchor, constant: 10),
seekToLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
])
}
Expand Down
Loading

0 comments on commit bcb99de

Please sign in to comment.