我正在开发iOS中的Cocos2D游戏,并在控制台中看到很多约束相关的警告。我在SO和其他网站上阅读过许多与限制相关的帖子,但一直未能解决这个问题。MPMoviePlayerController在Cocos2D中导致约束警告
我有没有 NIB文件,并没有在这个项目中使用XCodes用户界面生成器。 Cocos2D仅使用编程创建的全屏GLView。据我可以告诉所有这些约束来自与UIView本身交互的MPMoviePlayerController。
我使用的MPMoviePlayerController集成验证码:https://github.com/cocos2d/cocos2d-iphone-extensions/blob/master/Extensions/CCVideoPlayer/iOS/CCVideoPlayerImpliOS.m
了一些细微的变化,以显示视频非全屏,并得到它编译于iOS8上:
- (void) setupViewAndPlay
{
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
CGSize viewSize = [[CCDirector sharedDirector] viewSizeInPixels];
// We want to show these animations windowed - not full screen
// Native resolution of the movie is 480p = 640x360
CGRect videoFrame = CGRectMake(0, 0, 640, 360);
if (viewSize.height < 768)
{
// On the iphone play at 1/2 size
videoFrame = CGRectMake(0, 0, 320, 180);
}
videoFrame.origin.x = (viewSize.width - videoFrame.size.width)/2.0f;
videoFrame.origin.y = (viewSize.height - videoFrame.size.height)/2.0f;
[keyWindow addSubview: [_theMovie view]];
[[_theMovie view] setHidden: NO];
[[_theMovie view] setFrame: videoFrame];
[[_theMovie view] setCenter: keyWindow.center ];
[keyWindow setAutoresizesSubviews:NO];
[self updateOrientationWithOrientation: (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation]];
// Movie playback is asynchronous, so this method returns immediately.
[_theMovie play];
}
这里是我看到的警告:
2014-10-01 11:32:45.360 SpaceBotAlpha[182:4484] 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:0x17774f20 H:|-(34)-[MPKnockoutButton:0x177db4e0](LTR) (Names: '|':_UIBackdropContentView:0x18c7e040)>",
"<NSLayoutConstraint:0x17774f50 H:[MPKnockoutButton:0x177db4e0]-(34)-[MPDetailSlider:0x18cb1f60](LTR)>",
"<NSLayoutConstraint:0x17774f80 H:[MPDetailSlider:0x18cb1f60]-(34)-[UIView:0x18cb6780](LTR)>",
"<NSLayoutConstraint:0x17774fb0 UIView:0x18cb6780.right == _UIBackdropView:0x18caec50.right - 34>",
"<NSLayoutConstraint:0x18cafac0 H:|-(0)-[_UIBackdropView:0x18caec50] (Names: '|':MPVideoPlaybackOverlayView:0x1778ad80)>",
"<NSLayoutConstraint:0x18cc77b0 H:[_UIBackdropView:0x18caec50]-(0)-| (Names: '|':MPVideoPlaybackOverlayView:0x1778ad80)>",
"<NSAutoresizingMaskLayoutConstraint:0x1776da10 h=-&- v=-&- _UIBackdropContentView:0x18c7e040.midX == _UIBackdropView:0x18caec50.midX>",
"<NSAutoresizingMaskLayoutConstraint:0x1776da40 h=-&- v=-&- _UIBackdropContentView:0x18c7e040.width == _UIBackdropView:0x18caec50.width>",
"<NSAutoresizingMaskLayoutConstraint:0x177aa050 h=-&- v=-&- MPVideoPlaybackOverlayView:0x1778ad80.width == MPVideoContainerView:0x1778b8e0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x1775e480 h=-&- v=-&- MPVideoContainerView:0x1778b8e0.width == MPSwipableView:0x18cba6f0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x177a8ce0 h=-&- v=-&- MPSwipableView:0x18cba6f0.width == MPMovieView:0x177c7eb0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x17766310 h=--& v=--& H:[MPMovieView:0x177c7eb0(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17774f50 H:[MPKnockoutButton:0x177db4e0]-(34)-[MPDetailSlider:0x18cb1f60](LTR)>
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.
我发现有关约束的所有帖子都假设已经使用了界面构建器。
任何线索?谢谢!
万一有人发现了这个帖子寻找有关旋转的信息:我发现了一些在上iOS8上的MPMoviePlayerController
奇似乎自动旋转到正确的方向,如果我离开updateOrientationWithOrientation
方法,是(请参阅GitHub链接),然后以90度出现所需内容。所以在iOS8上,我检测updateOrientationWithOrientation内的版本,并在iOS8上不做任何事情而退出。
您是否阅读了该消息并查看了translatesAutoResizingMaskIntoConstraints? – LearnCocos2D 2014-10-01 07:29:32
我尝试设置为YES,并且没有translatesAutoResizingMaskIntoConstraints开关,但它没有帮助。这个问题仍然在发生,我仍然在控制台中收到相同的垃圾邮件。 – Sez 2014-10-18 03:56:22
我刚刚遇到了这个问题,据我所知它是iOS 8.x中的一个错误。有关的约束在MPMoviePlayer视图层次结构中下降了。理论上讲,你可以深入研究并设置他们的翻译自动化MakesMaskIntoConstraints = NO,但我个人选择让它独立。 – 2014-10-28 17:37:07