简体   繁体   English

AVPlayerViewController-无自动版式-无法同时满足约束。

[英]AVPlayerViewController - No Auto Layout - Unable to simultaneously satisfy constraints.

In my project I have created a ViewController and created a class as "AVPlayerViewController" in order to show videos. 在我的项目中,我创建了一个ViewController并创建了一个类“ AVPlayerViewController”以显示视频。

The code works and I am able to see the videos however, I get some constraints warnings in the console. 该代码可以正常工作,并且能够观看视频,但是,控制台中出现一些约束警告。

My project is working without AutoLayout and I use AutoResizing. 我的项目在没有AutoLayout的情况下工作,并且使用了AutoResizing。 I have tried the code: 我已经尝试了代码:

self.view.translatesAutoresizingMaskIntoConstraints = false

but the warnings are not going away and the controls of the video player move to the top of the screen . 但是警告并没有消失,视频播放器的控件移到屏幕顶部。

There warnings are: 有警告:

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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x1475c4540 h=-&- v=-&- _UIBackdropContentView:0x147443880.width == _UIBackdropView:0x147436a30.width>",
    "<NSLayoutConstraint:0x1475b38f0 H:|-(0)-[_UIBackdropView:0x147436a30]   (Names: '|':UIView:0x1474368d0 )>",
    "<NSLayoutConstraint:0x1475b3980 H:[_UIBackdropView:0x147436a30]-(0)-|   (Names: '|':UIView:0x1474368d0 )>",
    "<NSLayoutConstraint:0x1475b3650 H:|-(0)-[UIView:0x1474368d0]   (Names: '|':AVAlphaUpdatingView:0x14744db30 )>",
    "<NSLayoutConstraint:0x1475b36d0 H:[UIView:0x1474368d0]-(0)-|   (Names: '|':AVAlphaUpdatingView:0x14744db30 )>",
    "<NSLayoutConstraint:0x1475c7670 H:|-(15)-[UIView:0x1474435c0](LTR)   (Names: '|':_UIBackdropContentView:0x147443880 )>",
    "<NSLayoutConstraint:0x1475c54d0 UIView:0x147443b40.right == _UIBackdropContentView:0x147443880.right>",
    "<NSLayoutConstraint:0x1475c7a40 UIView:0x1474435c0.right == UIView:0x147443b40.left - 10>",
    "<NSLayoutConstraint:0x1475c4da0 'UIView-Encapsulated-Layout-Width' H:[AVAlphaUpdatingView:0x14744db30(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1475b3980 H:[_UIBackdropView:0x147436a30]-(0)-|   (Names: '|':UIView:0x1474368d0 )>

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

Any Idea what to do? 任何想法怎么办?

As per this answer Unable to simultaneously satisfy constraints Warnings with AVPlayerViewController embedded in storyboard the solution seems to be to set showsPlayBackControls off on the PlayerController and then add it to the view. 按照这个答案无法同时满足约束条件将AVPlayerViewController嵌入在情节提要中, 警告的解决方案似乎是在PlayerController上将showPlayBackControls设置为off,然后将其添加到视图中。

Once you have an AVPlayer item, you can show the player controls again (assuming you need them). 拥有AVPlayer物品后,您可以再次显示播放器控件(假设您需要它们)。

I suspect that a valid AVPlayer item is needed in order for the player control constraints to be properly satisfied. 我怀疑需要有效的AVPlayer项才能正确满足播放器控制约束。

I had this exact same issue and managed to fix it by making this change. 我遇到了完全相同的问题,并通过进行此更改设法解决了该问题。 Good luck! 祝好运!

Strangely enough, what you do is create a second view under your main view, and then add your player view as a subview to that. 奇怪的是,您要做的是在主视图下创建第二个视图,然后将播放器视图添加为该视图的子视图。

This very problem took me an entire day to solve a month ago, and that's how it got solved. 这个问题花了我整整一个月的时间才能解决,这就是解决问题的方式。 You must remove any code that auto resizes constraints, though. 但是,您必须删除任何会自动调整约束大小的代码。

If you are programmatically creating the view for your view controller, add the AVPlayerViewController as a child view controller and its view as a subview in loadView() method instead of viewDidLoad(). 如果要通过编程方式为视图控制器创建视图,请在loadView()方法(而不是viewDidLoad())中将AVPlayerViewController添加为子视图控制器,并将其视图添加为子视图。 No need to hide playback controls. 无需隐藏播放控件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么会收到错误消息“无法同时满足约束条件”。 自动布局? - Why do I receive an error that says 'Unable to simultaneously satisfy constraints.' for auto layout? 无法同时满足约束。 斯威夫特用户界面 - Unable to simultaneously satisfy constraints. SwiftUI iOS自动版式无法同时满足约束 - iOS Auto Layout Unable to simultaneously satisfy constraints 无法同时满足约束。 可能至少是限制之一 - Unable to simultaneously satisfy constraints. Probably at least one of the constraints 无法同时满足约束。 前导和尾随约束冲突 - Unable to simultaneously satisfy constraints. Leading and Trailing constraints conflicts 以编程方式应用自动布局约束时无法同时满足约束 - Unable to simultaneously satisfy constraints while applying auto layout constraints programatically SwiftUI:VStack 中的 Text + TextField 导致“无法同时满足约束”。 - SwiftUI: Text + TextField in VStack results in “Unable to simultaneously satisfy constraints.” 原型收集视图单元格“无法同时满足约束。”警告 - Prototyped collection view cell “Unable to simultaneously satisfy constraints.” warning Xamarin.iOS SWTableViewCell中的“无法同时满足约束。” - “Unable to simultaneously satisfy constraints.” in SWTableViewCell for Xamarin.iOS 以编程方式尝试NSLayoutContraint给出“无法同时满足约束”。 - Programmatically attempting NSLayoutContraint gives “Unable to simultaneously satisfy constraints.”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM