【问题标题】:Embed SDL's view into UIViewController将 SDL 的视图嵌入 UIViewController
【发布时间】:2014-10-11 18:04:48
【问题描述】:

我在 iOS 上看到的一些 SDL 演示,所有的渲染都发生在 SDL_Window 内部,而不是 UIWindow。但是,由于大多数 iOS 应用程序都是基于一个 UIWindow 建模的。我想将 iOS 与 SDL 集成,并将 SDL 的窗口(或 SDL 的视图)嵌入 UIViewController 的视图中。这是如何实现的?

我已经发布了我的问题here 并且还看到了 michelleC 的以下comment 说明以下内容,但我不知道如何编写 michelleC 提到的内容。我无权在他们的论坛上发帖/回复。

我很容易掌握 sdl 窗口并添加视图控制器 到它,或获取封装的 sdl 视图并将其添加到视图中 控制器。

到目前为止,我所做的是修改 SDL_uikitviewcontroller.m 以重新定位/调整 SDL_Window 的视图:

- (void)viewDidLayoutSubviews
{
    CGRect newFrame = self.view.frame;
    newFrame.size.height = newFrame.size.height - 100;
    newFrame.size.width  = newFrame.size.width - 50;
    newFrame.origin.x = 25.0f;
    self.view.frame = newFrame;

    SDLUIKitDelegate *appDelegate = [SDLUIKitDelegate sharedAppDelegate];
    [appDelegate embedView:self.view];
}

然后我将该视图传递给 SDL_uikitappdelegate.m 中的一个函数,它会将 SDL_Window 的视图添加为 UIViewController 的子视图。但是,我遇到了错误。

- (void) embedView:(UIView*)vw {
    [vw removeFromSuperview];

    CGRect frame = vw.frame;
    frame.origin.x = 56.0f;
    vw.frame = frame;

    [self.window.rootViewController.view addSubview:vw];
}

2014-10-11 12:53:51.723 Happy[16403:614428] -[SDLUIKitDelegate window]: unrecognized selector sent to instance 0x7fbf11500d60
2014-10-11 12:53:51.725 Happy[16403:614428] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SDLUIKitDelegate window]: unrecognized selector sent to instance 0x7fbf11500d60'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001115323f5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000111e04bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000011153950d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000011149160f ___forwarding___ + 495
    4   CoreFoundation                      0x0000000111491398 _CF_forwarding_prep_0 + 120
    5   Happy                               0x000000010f227eb1 -[SDLUIKitDelegate embedView:] + 289
    6   Happy                               0x000000010f26f968 -[SDL_uikitviewcontroller viewDidLayoutSubviews] + 1400
    7   UIKit                               0x000000010fcee1cc -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 572
    8   QuartzCore                          0x0000000111284f98 -[CALayer layoutSublayers] + 150
    9   QuartzCore                          0x0000000111279bbe _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    10  QuartzCore                          0x0000000111279a2e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    11  QuartzCore                          0x00000001111e7ade _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
    12  QuartzCore                          0x00000001111e8bea _ZN2CA11Transaction6commitEv + 390
    13  UIKit                               0x000000010fc8adb0 -[UIApplication _sendOrderedOutContextsAndInvalidate:] + 99
    14  UIKit                               0x000000010fc8ad2b orderOutContextObserverCallout + 34
    15  CoreFoundation                      0x0000000111467347 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    16  CoreFoundation                      0x00000001114672a0 __CFRunLoopDoObservers + 368
    17  CoreFoundation                      0x000000011145c9e4 CFRunLoopRunSpecific + 436
    18  Happy                               0x000000010f223667 UIKit_PumpEvents + 71
    19  Happy                               0x000000010f1b0b10 SDL_PumpEvents + 48
    20  Happy                               0x000000010f1b0b88 SDL_WaitEventTimeout + 56
    21  Happy                               0x000000010f1b0b4a SDL_PollEvent + 26
    22  Happy                               0x000000010f16d883 SDL_main + 195
    23  Happy                               0x000000010f227d3e -[SDLUIKitDelegate postFinishLaunch] + 46
    24  Foundation                          0x000000010f81ea75 __NSFireDelayedPerform + 387
    25  CoreFoundation                      0x000000011149a4e4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
    26  CoreFoundation                      0x000000011149a0a5 __CFRunLoopDoTimer + 1045
    27  CoreFoundation                      0x000000011145d3dd __CFRunLoopRun + 1901
    28  CoreFoundation                      0x000000011145ca06 CFRunLoopRunSpecific + 470
    29  GraphicsServices                    0x00000001130209f0 GSEventRunModal + 161
    30  UIKit                               0x000000010fc75550 UIApplicationMain + 1282
    31  Happy                               0x000000010f227608 main + 328
    32  libdyld.dylib                       0x00000001121c6145 start + 1
    33  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

【问题讨论】:

    标签: ios 3d sdl


    【解决方案1】:

    问题是由于我的代码引用了错误的变量。 embedView: 中的以下行应该被替换:

    [self.window.rootViewController.view addSubview:vw];

    [myWindow.rootViewController.view addSubview:vw];

    【讨论】:

    • 嗨 Loc Pham,我还想将 storyBoard 与我的 SDL 游戏集成。但是大部分文章只是 1 次 SDL Launch,我想知道这对 swift 3 是否可行?如果没有,我需要一个桥头代替。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-25
    • 2013-07-04
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多