gpt4 book ai didi

ios - swift 3 错误 : Type 'AVLayerVideoGravity' has no member 'resizeAspectFill'

转载 作者:可可西里 更新时间:2023-11-01 05:03:39 30 4
gpt4 key购买 nike

我正在使用 Swift 3 开发一个 iOS 应用程序,我在后台播放视频。我的代码工作完全正常,直到随机出现错误消息:

Type AVLayerVideoGravity aka (NSString) has no member resizeAspectFill

出现。我完全不明白为什么 resizeAspectFill 不再被识别。有什么我想念的吗?我试过清理我的项目,但这并没有解决任何问题。任何帮助将不胜感激 :)下面是代码:

import Foundation
import AVFoundation
import UIKit

class HomeViewController: UIViewController {
// MARK: Properties
var avPlayer: AVPlayer!
var avPlayerLayer: AVPlayerLayer!
var paused: Bool = false

var enterButton: UIButton! = UIButton()

override func viewDidLoad() {
super.viewDidLoad()
self.title = "Welcome"

let theURL = Bundle.main.url(forResource:"hannah", withExtension: "mp4")

avPlayer = AVPlayer(url: theURL!)
avPlayerLayer = AVPlayerLayer(player: avPlayer)
avPlayerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill

avPlayer.volume = 0
avPlayer.actionAtItemEnd = .none

avPlayerLayer.frame = view.layer.bounds
view.backgroundColor = .clear
view.layer.insertSublayer(avPlayerLayer, at: 0)

NotificationCenter.default.addObserver(self,
selector: #selector(playerItemDidReachEnd(notification:)),
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
object: avPlayer.currentItem)

最佳答案

来自documentation of AVPlayerLayer (不幸的是,该链接重定向到 Swift 4 版本。要查看更改,请在右上角启用显示 API 更改)。

The video gravity determines how the video content is scaled or stretched within the player layer’s bounds. The player layer supports the following video gravity values:

  • AVLayerVideoGravityResizeAspect

  • AVLayerVideoGravityResizeAspectFill

  • AVLayerVideoGravityResize

The default value is AVLayerVideoGravityResizeAspect.


您所指的枚举案例属于 Swift 4

关于ios - swift 3 错误 : Type 'AVLayerVideoGravity' has no member 'resizeAspectFill' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44620366/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com