ios - MPMoviePlayerController 在 Cocos2D 中导致约束警告

标签 ios objective-c cocos2d-iphone nslayoutconstraint

我正在为 iOS 使用 Cocos2D 开发游戏,并在控制台中看到许多与约束相关的警告。我已经在 SO 和其他网站上阅读了许多与约束相关的帖子,但未能解决这个问题。

没有 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 上不做任何事情就退出。

最佳答案

我遇到了同样的约束问题。但是,sez 的回答对我不起作用,所以我进行了更深入的研究。在我的例子中,问题是在设置视频 Controller View 的框架并将其添加到 super View 之前调用 [videoConroller prepareToPlay]

我正在创建我的 MPMoviePlayerController 的实例,并在 viewDidLoad 中调用 prepareToPlay,因为此时我有 url。但是,我一直等到 viewDidAppear 实际调整视频播放器的大小并将其添加到 View 层次结构中。

在将 View 添加到层​​次结构之后,只需将该方法调用移动到即可解决我的问题。此外,我能够拥有一个与父 View 的边界不匹配的框架。

关于ios - MPMoviePlayerController 在 Cocos2D 中导致约束警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26133251/

相关文章:

ios - 如何在 iOS 9.1 设​​备上运行 swift 1.2 代码?

ios - 如何在 Swift 中处理深色模式的自定义颜色

ios - NSFileManager createFileAtPath 在 iPad 上失败但在模拟器上工作

objective-c - Unix 时间戳未正确转换为 NSDate

ios - 我们可以从后台线程更新UI吗?

objective-c - 贝塞尔路径解决性能问题

ios - 创建连续动画

ios - 如何在 Cocos2d 中播放音频文件的特定部分

iphone - cocos2d游戏如何实现暂停/恢复?

iphone - MPMoviePlayerController 进入 View