自动调整AVPlayerViewController

时间:2016-06-22 15:01:55

标签: ios swift avplayer nslayoutconstraint avplayerviewcontroller

我像这样添加AVPlayerViewController

var mainVideoView = AVPlayerViewController()
var player = AVPlayer()

override func viewDidAppear(animated: Bool) {
    player = AVPlayer(URL : self.videoURL!)
    mainVideoView.player = player
}

我对它设置了以下约束:

    mainVideoView.view.translatesAutoresizingMaskIntoConstraints = false

self.view.addConstraint(NSLayoutConstraint(item: mainVideoView.view, attribute: .Top, relatedBy: .Equal, toItem: self.view, attribute: .Top, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: mainVideoView.view, attribute: .Leading, relatedBy: .Equal, toItem: self.view, attribute: .Leading, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: mainVideoView.view, attribute: .Trailing, relatedBy: .Equal, toItem: self.view, attribute: .Trailing, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: mainVideoView.view, attribute: .CenterX, relatedBy: .Equal, toItem: self.view, attribute: .CenterX, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: mainVideoView.view, attribute: .Bottom, relatedBy: .Equal, toItem: self.containerView, attribute: .Top, multiplier: 1, constant: 0))
self.view.sendSubviewToBack(mainVideoView.view)

它看起来似乎很好,但它会抛出所有这些错误消息:

	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:0x7fee060cfb60 _UIBackdropContentView:0x7fee03ea54f0.width == _UIBackdropView:0x7fee03ea5070.width>",
    "<NSLayoutConstraint:0x7fee060d94a0 UIActivityIndicatorView:0x7fee03cb9020.leading == UIView:0x7fee03c9d1a0.leading>",
    "<NSLayoutConstraint:0x7fee060d45b0 UILabel:0x7fee06b69670.leading == UIActivityIndicatorView:0x7fee03cb9020.trailing + 10>",
    "<NSLayoutConstraint:0x7fee06095850 UIView:0x7fee03c9d1a0.trailing == UILabel:0x7fee06b69670.trailing>",
    "<NSLayoutConstraint:0x7fee03cce1d0 UIView:0x7fee03c9d1a0.leading >= AVLoadingIndicatorView:0x7fee060d6e40.leading>",
    "<NSLayoutConstraint:0x7fee0608dc10 UIView:0x7fee03c9d1a0.centerX == AVLoadingIndicatorView:0x7fee060d6e40.centerX>",
    "<NSLayoutConstraint:0x7fee060c0310 UIView:0x7fee03e37ff0.leading == _UIBackdropContentView:0x7fee03ea54f0.leading>",
    "<NSLayoutConstraint:0x7fee060ded10 _UIBackdropContentView:0x7fee03ea54f0.trailing == UIView:0x7fee03e37ff0.trailing>",
    "<NSLayoutConstraint:0x7fee03cb6e30 _UIBackdropView:0x7fee03ea5070.leading == UIView:0x7fee06592af0.leading>",
    "<NSLayoutConstraint:0x7fee06071710 UIView:0x7fee06592af0.trailing == _UIBackdropView:0x7fee03ea5070.trailing>",
    "<NSLayoutConstraint:0x7fee060d2be0 UIView:0x7fee06592af0.leading == AVAlphaUpdatingView:0x7fee03e41050.leading>",
    "<NSLayoutConstraint:0x7fee060034d0 AVAlphaUpdatingView:0x7fee03e41050.trailing == UIView:0x7fee06592af0.trailing>",
    "<NSLayoutConstraint:0x7fee06a0e9a0 AVButton:0x7fee03ea5660.left == UIView:0x7fee03e37ff0.left + 14>",
    "<NSLayoutConstraint:0x7fee06a10b90 AVButton:0x7fee03e7ebf0.right == AVButton:0x7fee060acaa0.left - 10>",
    "<NSLayoutConstraint:0x7fee06a0efa0 AVButton:0x7fee060acaa0.right == AVButton:0x7fee06b72d50.left - 10>",
    "<NSLayoutConstraint:0x7fee06a10c30 AVButton:0x7fee06b72d50.right == UIView:0x7fee03e37ff0.right - 14>",
    "<NSLayoutConstraint:0x7fee06a10f70 AVLoadingIndicatorView:0x7fee060d6e40.left >= AVButton:0x7fee03ea5660.right + 15>",
    "<NSLayoutConstraint:0x7fee06a10fc0 AVLoadingIndicatorView:0x7fee060d6e40.right <= AVButton:0x7fee03e7ebf0.left - 15>",
    "<NSLayoutConstraint:0x7fee03ccbe70 AVAlphaUpdatingView:0x7fee03e41050.width == 0>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fee060d45b0 UILabel:0x7fee06b69670.leading == UIActivityIndicatorView:0x7fee03cb9020.trailing + 10>

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.
2016-06-22 15:57:04.927 City[1857:61566] 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:0x7fee060cfb60 _UIBackdropContentView:0x7fee03ea54f0.width == _UIBackdropView:0x7fee03ea5070.width>",
    "<NSLayoutConstraint:0x7fee060c0310 UIView:0x7fee03e37ff0.leading == _UIBackdropContentView:0x7fee03ea54f0.leading>",
    "<NSLayoutConstraint:0x7fee060ded10 _UIBackdropContentView:0x7fee03ea54f0.trailing == UIView:0x7fee03e37ff0.trailing>",
    "<NSLayoutConstraint:0x7fee03cb6e30 _UIBackdropView:0x7fee03ea5070.leading == UIView:0x7fee06592af0.leading>",
    "<NSLayoutConstraint:0x7fee06071710 UIView:0x7fee06592af0.trailing == _UIBackdropView:0x7fee03ea5070.trailing>",
    "<NSLayoutConstraint:0x7fee060d2be0 UIView:0x7fee06592af0.leading == AVAlphaUpdatingView:0x7fee03e41050.leading>",
    "<NSLayoutConstraint:0x7fee060034d0 AVAlphaUpdatingView:0x7fee03e41050.trailing == UIView:0x7fee06592af0.trailing>",
    "<NSLayoutConstraint:0x7fee06a0e9a0 AVButton:0x7fee03ea5660.left == UIView:0x7fee03e37ff0.left + 14>",
    "<NSLayoutConstraint:0x7fee06a10b90 AVButton:0x7fee03e7ebf0.right == AVButton:0x7fee060acaa0.left - 10>",
    "<NSLayoutConstraint:0x7fee06a0efa0 AVButton:0x7fee060acaa0.right == AVButton:0x7fee06b72d50.left - 10>",
    "<NSLayoutConstraint:0x7fee06a10c30 AVButton:0x7fee06b72d50.right == UIView:0x7fee03e37ff0.right - 14>",
    "<NSLayoutConstraint:0x7fee06a10f70 AVLoadingIndicatorView:0x7fee060d6e40.left >= AVButton:0x7fee03ea5660.right + 15>",
    "<NSLayoutConstraint:0x7fee06a10fc0 AVLoadingIndicatorView:0x7fee060d6e40.right <= AVButton:0x7fee03e7ebf0.left - 15>",
    "<NSLayoutConstraint:0x7fee03ccbe70 AVAlphaUpdatingView:0x7fee03e41050.width == 0>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fee06a10f70 AVLoadingIndicatorView:0x7fee060d6e40.left >= AVButton:0x7fee03ea5660.right + 15>

我不知道它是什么自动调整,因为我禁用了它。

0 个答案:

没有答案