我正在尝试这样配置AVPlayerViewController
:
在- (void) willMoveToSuperview:(UIView *)newSuperview
我称之为代码:
if(self.moviePlayerController == nil) {
self.moviePlayerController = [[AVPlayerViewController alloc] init];
[self.view addSubview: [self.moviePlayerController view]];
[self.view setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.moviePlayerController.view setTranslatesAutoresizingMaskIntoConstraints:NO];
NSDictionary *views = @{ @"selfview" : self.view, @"movieControllerView" : [self moviePlayerController].view};
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[movieControllerView]|"
options:0
metrics:nil
views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[movieControllerView]|"
options:0
metrics:nil
views:views]];
}
但是当创建播放器时,我得到了这个异常:
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:0x1499d1730 AVPlayerView:0x149885150.(null) == TSNView:0x14996bca0.(null) - 110>",
"<NSLayoutConstraint:0x1498bf480 AVPlayerView:0x149885150.leading == TSNView:0x14996bca0.leading>",
"<NSLayoutConstraint:0x1498bc800 UIView:0x14996bca0.trailing == AVPlayerView:0x149885150.trailing>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1498bc800 UIView:0x14996bca0.trailing == AVPlayerView:0x149885150.trailing>
该代码可以正常工作MPMoviePlayerController
。这是我可以AVPlayerViewController's
使用自动布局将视图嵌套在另一个视图中的正确方法吗?