ios - 如何为 AVPlayerViewController 设置布局约束?

标签 ios objective-c layout constraints avplayerviewcontroller

我已经设置了 AVPlayerViewController。如何设置 AVPlayerViewController 的布局约束?谢谢!

启动APP控制台显示这个警告:

2017-04-14 10:51:34.900747 robot_blue[12510:4193750] [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. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x174482170 _UIBackdropContentView:0x101fb3e60.width == _UIBackdropView:0x101fb2990.width>",
    "<NSLayoutConstraint:0x17048a8c0 UILabel:0x101fc9b00.leading == _UIBackdropContentView:0x101fb3e60.leading + 14>",
    "<NSLayoutConstraint:0x17048a910 _UIBackdropContentView:0x101fb3e60.trailing == UILabel:0x101fc9b00.trailing + 14>",
    "<NSLayoutConstraint:0x17048a5a0 _UIBackdropView:0x101fb2990.leading == UIView:0x101fb27f0.leading>",
    "<NSLayoutConstraint:0x17048a5f0 UIView:0x101fb27f0.trailing == _UIBackdropView:0x101fb2990.trailing>",
    "<NSLayoutConstraint:0x17048a410 UIView:0x101fb27f0.leading == AVAlphaUpdatingView:0x101fb2450.leading>",
    "<NSLayoutConstraint:0x17048a460 AVAlphaUpdatingView:0x101fb2450.trailing == UIView:0x101fb27f0.trailing>",
    "<NSLayoutConstraint:0x174482260 AVAlphaUpdatingView:0x101fb2450.width == 0>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x17048a910 _UIBackdropContentView:0x101fb3e60.trailing == UILabel:0x101fc9b00.trailing + 14>

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.
2017-04-14 10:51:34.901441 robot_blue[12510:4193750] [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. 
(
    "<NSLayoutConstraint:0x17048a4b0 UIView:0x101fb27f0.top >= AVAlphaUpdatingView:0x101fb2450.top>",
    "<NSLayoutConstraint:0x17048a500 AVAlphaUpdatingView:0x101fb2450.bottom == UIView:0x101fb27f0.bottom>",
    "<NSLayoutConstraint:0x17048a550 UIView:0x101fb27f0.height == 44>",
    "<NSLayoutConstraint:0x174481bd0 AVAlphaUpdatingView:0x101fb2450.height == 0>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x17048a500 AVAlphaUpdatingView:0x101fb2450.bottom == UIView:0x101fb27f0.bottom>

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.
2017-04-14 10:51:34.902242 robot_blue[12510:4193750] [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. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x174482170 _UIBackdropContentView:0x101fb3e60.width == _UIBackdropView:0x101fb2990.width>",
    "<NSLayoutConstraint:0x17048a6e0 UIView:0x101fb3b20.leading == _UIBackdropContentView:0x101fb3e60.leading>",
    "<NSLayoutConstraint:0x17048a730 _UIBackdropContentView:0x101fb3e60.trailing == UIView:0x101fb3b20.trailing>",
    "<NSLayoutConstraint:0x17048a5a0 _UIBackdropView:0x101fb2990.leading == UIView:0x101fb27f0.leading>",
    "<NSLayoutConstraint:0x17048a5f0 UIView:0x101fb27f0.trailing == _UIBackdropView:0x101fb2990.trailing>",
    "<NSLayoutConstraint:0x17048a410 UIView:0x101fb27f0.leading == AVAlphaUpdatingView:0x101fb2450.leading>",
    "<NSLayoutConstraint:0x17048a460 AVAlphaUpdatingView:0x101fb2450.trailing == UIView:0x101fb27f0.trailing>",
    "<NSLayoutConstraint:0x174482440 AVButton:0x101fb2e50.left == UIView:0x101fb3b20.left + 14>",
    "<NSLayoutConstraint:0x1744824e0 UILabel:0x101fb4000.left == AVButton:0x101fb2e50.right + 15>",
    "<NSLayoutConstraint:0x174482580 AVScrubber:0x101fc6900.left == UILabel:0x101fb4000.right + 12>",
    "<NSLayoutConstraint:0x1744825d0 AVScrubber:0x101fc6900.right == UILabel:0x1020d1280.left - 12>",
    "<NSLayoutConstraint:0x1744826c0 UILabel:0x1020d1280.right == AVButton:0x1020d1510.left - 15>",
    "<NSLayoutConstraint:0x174482760 AVButton:0x1020d1510.right == AVButton:0x1020d1a30.left - 10>",
    "<NSLayoutConstraint:0x174482670 AVButton:0x1020d1a30.right == AVButton:0x1020d22a0.left - 10>",
    "<NSLayoutConstraint:0x174482850 AVButton:0x1020d22a0.right == UIView:0x101fb3b20.right - 14>",
    "<NSLayoutConstraint:0x174482260 AVAlphaUpdatingView:0x101fb2450.width == 0>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1744824e0 UILabel:0x101fb4000.left == AVButton:0x101fb2e50.right + 15>

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.
2017-04-14 10:51:34.903110 robot_blue[12510:4193750] [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. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x174482170 _UIBackdropContentView:0x101fb3e60.width == _UIBackdropView:0x101fb2990.width>",
    "<NSLayoutConstraint:0x17048a6e0 UIView:0x101fb3b20.leading == _UIBackdropContentView:0x101fb3e60.leading>",
    "<NSLayoutConstraint:0x17048a730 _UIBackdropContentView:0x101fb3e60.trailing == UIView:0x101fb3b20.trailing>",
    "<NSLayoutConstraint:0x17048a5a0 _UIBackdropView:0x101fb2990.leading == UIView:0x101fb27f0.leading>",
    "<NSLayoutConstraint:0x17048a5f0 UIView:0x101fb27f0.trailing == _UIBackdropView:0x101fb2990.trailing>",
    "<NSLayoutConstraint:0x17048a410 UIView:0x101fb27f0.leading == AVAlphaUpdatingView:0x101fb2450.leading>",
    "<NSLayoutConstraint:0x17048a460 AVAlphaUpdatingView:0x101fb2450.trailing == UIView:0x101fb27f0.trailing>",
    "<NSLayoutConstraint:0x174482440 AVButton:0x101fb2e50.left == UIView:0x101fb3b20.left + 14>",
    "<NSLayoutConstraint:0x174482760 AVButton:0x1020d1510.right == AVButton:0x1020d1a30.left - 10>",
    "<NSLayoutConstraint:0x174482670 AVButton:0x1020d1a30.right == AVButton:0x1020d22a0.left - 10>",
    "<NSLayoutConstraint:0x174482850 AVButton:0x1020d22a0.right == UIView:0x101fb3b20.right - 14>",
    "<NSLayoutConstraint:0x174482a80 AVLoadingIndicatorView:0x101fc8c80.left >= AVButton:0x101fb2e50.right + 15>",
    "<NSLayoutConstraint:0x174482ad0 AVLoadingIndicatorView:0x101fc8c80.right <= AVButton:0x1020d1510.left - 15>",
    "<NSLayoutConstraint:0x174482260 AVAlphaUpdatingView:0x101fb2450.width == 0>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x174482a80 AVLoadingIndicatorView:0x101fc8c80.left >= AVButton:0x101fb2e50.right + 15>

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.

最佳答案

AVPlayerViewController View 上设置标志 translatesAutoresizingMaskIntoConstraints = false。例如:

let playerViewController = AVPlayerViewController()
playerViewController.view.translatesAutoresizingMaskIntoConstraints = false

然后对该 View 设置约束。

如果您希望 AVPlayerViewController 占据您自己的 UIViewController 的 subview ,则使 AVPlayerViewController 成为您的 View Controller 的 subview :

self.addChildViewController(playerViewController)
self.view.addSubview(playerViewController.view)
playerViewController.didMove(toParentViewController:self)

关于ios - 如何为 AVPlayerViewController 设置布局约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43404725/

相关文章:

iphone - 在 4 或 5 个 x/y 坐标之间随机移动 UILabel

java - 创建 JFrame 以显示棋盘

css - 仅当顶部栏粘在顶部时如何显示元素? - Zurb 基金会

ios - 如何在没有操作队列的情况下取消 GCD 中的请求

ios - 分段控件更改时更新 rightBarButtonItems

ios - UICollectionViewController 未调整与 InputAccessoryView 一起显示的键盘

ios - NSMutableArray 与 NSDictionary 到 NSMutableDictionary

iphone - CGContextSaveGState 无效上下文

objective-c - 如何在行中的单元格被删除之前动态更改 UITableViewCell 标签?

android - fragment 选项卡未使用所有空间