gpt4 book ai didi

ios - Swift 4 使用 AVPlayerViewController() 时无法同时满足约束条件

转载 作者:搜寻专家 更新时间:2023-10-31 23:07:25 27 4
gpt4 key购买 nike

我正在以编程方式为我的应用添加介绍视频。我收到以下警告。任何想法我做错了什么? 我对 swift 和 iOS 开发还很陌生。

2018-04-19 13:11:56.295952+0200 [1779:395252] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "", "", " (active, names: '|':UIStackView:0x15dd29110 )>", "", " (active, names: '|':UIStackView:0x15dd29110 )>" )

Will attempt to recover by breaking constraint

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful. 2018-04-19 13:11:56.296790+0200 [1779:395252] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "", "", "", "UILayoutGuide:0x1d41bd180'UIViewLayoutMarginsGuide'
(active, names: '|':UIStackView:0x15dd29110 )>", " (active, names: '|':UIStackView:0x15dd29110 )>" )

Will attempt to recover by breaking constraint

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.

var movieController: AVPlayer?
let playerViewController = AVPlayerViewController()

override func viewDidLoad() {
playVideo()
}

func playVideo() {
let path = Bundle.main.path(forResource: appData.videoFile, ofType: appData.videoExtension)
let url = URL(fileURLWithPath: path!)
movieController = AVPlayer(url: url)
NotificationCenter.default.addObserver(self, selector:#selector(movieFinished),name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: movieController?.currentItem)
playerViewController.player = self.movieController
playerViewController.delegate = self
playerViewController.view.frame = self.view.bounds
playerViewController.showsPlaybackControls = false
playerViewController.videoGravity = "AVLayerVideoGravityResizeAspectFill"
playerViewController.view.translatesAutoresizingMaskIntoConstraints = false
playerViewController.player?.play()
self.view.addSubview(playerViewController.view)
}

@objc func movieFinished() {
let value = UIInterfaceOrientation.portrait.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
UIViewController.attemptRotationToDeviceOrientation()
UIView.animate(withDuration: 1.5, delay: 0, options: .curveEaseIn, animations: {
self.playerViewController.view.alpha = 0.0
}, completion: { (finished: Bool) in
self.playerViewController.view.removeFromSuperview()
})
}

最佳答案

我最终通过使用 AVPlayerLayer 和 AVPlayerItem 解决了这个问题。

var player:AVPlayer?
var playerItem:AVPlayerItem?
let playerLayer:AVPlayerLayer? = nil

override func loadView() {
super.loadView()
startWebiew()
}

func playVideo() {
let path = Bundle.main.path(forResource: appData.videoFile, ofType: appData.videoExtension)
let url = URL(fileURLWithPath: path!)
let playerItem:AVPlayerItem = AVPlayerItem(url: url)
player = AVPlayer(playerItem: playerItem)
let playerLayer=AVPlayerLayer(player: player!)
playerLayer.frame = view.bounds
playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
playerLayer.player?.play()
view.layer.addSublayer(playerLayer)

}

关于ios - Swift 4 使用 AVPlayerViewController() 时无法同时满足约束条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49919996/

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