如何设置AVPlayerViewController的布局约束?

问题描述:

我已经设置AVPlayerViewController.How为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. 
+0

尝试建议:'将尝试恢复打破约束' –

+0

@ Mr.Bista,谢谢。但是,我不解决这个问题。 –

设置你的AVPlayerViewControllerviewtranslatesAutoresizingMaskIntoConstraints = false。例如:

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

然后设置您的约束view

如果你想AVPlayerViewController占据自己UIViewController的子视图,然后进行AVPlayerViewController您的视图控制器的孩子:这条线下面给出

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