AVPlayerViewController - 无自动布局 - 无法同时满足约束条件。
AVPlayerViewController - No Auto Layout - Unable to simultaneously satisfy constraints.
在我的项目中,我创建了一个 ViewController 并创建了一个 class 作为 "AVPlayerViewController" 以显示视频。
代码有效,我可以看到视频,但是,我在控制台中收到一些限制警告。
我的项目在没有 AutoLayout 的情况下工作,我使用了 AutoResizing。我试过代码:
self.view.translatesAutoresizingMaskIntoConstraints = false
但警告并没有消失,视频播放器的控件移到了屏幕顶部。
有警告是:
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.
知道要做什么吗?
根据这个答案Unable to simultaneously satisfy constraints Warnings with AVPlayerViewController embedded in storyboard,解决方案似乎是在 PlayerController 上关闭 showsPlayBackControls,然后将其添加到视图中。
获得 AVPlayer 项目后,您可以再次显示播放器控件(假设您需要它们)。
我怀疑需要一个有效的 AVPlayer 项目才能正确满足播放器控制约束。
我遇到了完全相同的问题,并通过进行此更改设法解决了它。祝你好运!
奇怪的是,您所做的是在主视图下创建第二个视图,然后将播放器视图作为子视图添加到该视图。
这个问题一个月前花了我一整天的时间才解决,就这样解决了。不过,您必须删除任何自动调整约束大小的代码。
如果您以编程方式为视图控制器创建视图,请将 AVPlayerViewController 添加为子视图控制器,并将其视图添加为 loadView() 方法中的子视图,而不是 viewDidLoad()。无需隐藏播放控件。
在我的项目中,我创建了一个 ViewController 并创建了一个 class 作为 "AVPlayerViewController" 以显示视频。
代码有效,我可以看到视频,但是,我在控制台中收到一些限制警告。
我的项目在没有 AutoLayout 的情况下工作,我使用了 AutoResizing。我试过代码:
self.view.translatesAutoresizingMaskIntoConstraints = false
但警告并没有消失,视频播放器的控件移到了屏幕顶部。
有警告是:
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.
知道要做什么吗?
根据这个答案Unable to simultaneously satisfy constraints Warnings with AVPlayerViewController embedded in storyboard,解决方案似乎是在 PlayerController 上关闭 showsPlayBackControls,然后将其添加到视图中。
获得 AVPlayer 项目后,您可以再次显示播放器控件(假设您需要它们)。
我怀疑需要一个有效的 AVPlayer 项目才能正确满足播放器控制约束。
我遇到了完全相同的问题,并通过进行此更改设法解决了它。祝你好运!
奇怪的是,您所做的是在主视图下创建第二个视图,然后将播放器视图作为子视图添加到该视图。
这个问题一个月前花了我一整天的时间才解决,就这样解决了。不过,您必须删除任何自动调整约束大小的代码。
如果您以编程方式为视图控制器创建视图,请将 AVPlayerViewController 添加为子视图控制器,并将其视图添加为 loadView() 方法中的子视图,而不是 viewDidLoad()。无需隐藏播放控件。