我想CMTime字符串一个人类可读的。
所以我找到了下面的代码。
extension CMTime {
var durationText:String {
let totalSeconds = CMTimeGetSeconds(self)
let hours:Int = Int(totalSeconds / 3600)
let minutes:Int = Int(totalSeconds.truncatingRemainder(dividingBy: 3600) / 60)
let seconds:Int = Int(totalSeconds.truncatingRemainder(dividingBy: 60))
if hours > 0 {
return String(format: "%i:%02i:%02i", hours, minutes, seconds)
} else {
return String(format: "%02i:%02i", minutes, seconds)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有30 second视频文件。它的CMTime价值是17945。
我期待这个 durationText 00:30。
但结果是00:29。
和其他视频文件一样。
我应该修复什么??
我发现了一些奇怪的东西。
我创建了一个自定义 UICollectionViewCell 并在其中创建了一个标签。
我只对标签的顶部、前导和底部应用了自动布局。
class TestCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var label: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
}
Run Code Online (Sandbox Code Playgroud)
如果文本很长,它会像下面一样从屏幕上剪下来。
如果文本太长,我希望文本仅显示为“...”。
所以我像这样应用了traling自动布局。
然后, collectionViewCell 的宽度被破坏了。
这是我的代码。
我已经设置了委托,数据源。
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension ViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 20
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? TestCollectionViewCell else { return …Run Code Online (Sandbox Code Playgroud)