我正在尝试在url中播放iOS中的视频。我在故事板中添加了一个视图。我已经将它的位置视为 Bottom-Right 。我给的位置是我的videoPlayer和view一样。但是当我播放视频时,我得到错误
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)
(
"<NSLayoutConstraint:0x7ff4314c04c0 H:|-(34)-[MPKnockoutButton:0x7ff431660bc0](LTR) (Names: '|':_UIBackdropContentView:0x7ff431622240 )>",
"<NSLayoutConstraint:0x7ff4314d8ac0 H:[MPKnockoutButton:0x7ff431660bc0]-(34)-[MPDetailSlider:0x7ff43161aff0](LTR)>",
"<NSLayoutConstraint:0x7ff4314d8b10 H:[MPDetailSlider:0x7ff43161aff0]-(34)-[UIView:0x7ff43161e360](LTR)>",
"<NSLayoutConstraint:0x7ff4317803a0 UIView:0x7ff43161e360.right == _UIBackdropView:0x7ff431615440.right - 34>",
"<NSLayoutConstraint:0x7ff43161e780 H:|-(0)-[_UIBackdropView:0x7ff431615440] (Names: '|':MPVideoPlaybackOverlayView:0x7ff4316c8930 )>",
"<NSLayoutConstraint:0x7ff43161e7d0 H:[_UIBackdropView:0x7ff431615440]-(0)-| (Names: '|':MPVideoPlaybackOverlayView:0x7ff4316c8930 )>",
"<NSLayoutConstraint:0x7ff4317bbce0 '_UITemporaryLayoutWidth' H:[MPVideoPlaybackOverlayView:0x7ff4316c8930(111.5)]>",
"<NSAutoresizingMaskLayoutConstraint:0x7ff4317c9500 h=-&- v=-&- _UIBackdropContentView:0x7ff431622240.midX == _UIBackdropView:0x7ff431615440.midX>",
"<NSAutoresizingMaskLayoutConstraint:0x7ff4317c9550 h=-&- v=-&- _UIBackdropContentView:0x7ff431622240.width == _UIBackdropView:0x7ff431615440.width>"
)
播放视频的代码
NSURL *fileURL = [NSURL URLWithString:@"http://www.w3schools.com/html/movie.mp4"];
self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
CGRect movieFrame;
movieFrame.size = self.videoView.frame.size;
[self.moviePlayerController.view setFrame:movieFrame];
[self.moviePlayerController.view setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.videoView addSubview:self.moviePlayerController.view];
[self.videoView bringSubviewToFront:self.moviePlayerController.view];
[self.videoView addConstraint:[NSLayoutConstraint constraintWithItem:self.moviePlayerController.view
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.videoView
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0.0]];
[self.videoView addConstraint:[NSLayoutConstraint constraintWithItem:self.moviePlayerController.view
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:self.videoView
attribute:NSLayoutAttributeTrailing
multiplier:1.0
constant:0.0]];
[self.videoView addConstraint:[NSLayoutConstraint constraintWithItem:self.moviePlayerController.view
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.videoView
attribute:NSLayoutAttributeLeading
multiplier:1.0
constant:0.0]];
[self.videoView addConstraint:[NSLayoutConstraint constraintWithItem:self.moviePlayerController.view
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.videoView
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:0.0]];
[self.moviePlayerController play];