2014-10-11 64 views
1

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

我已经发布我的问题here,也看到以下comment michelleC陈述以下,但我不知道如何编码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 

回答

1

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

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

[myWindow.rootViewController.view addSubview:VW];

+0

嗨Loc Pham,我也想把storyBoard和我的SDL游戏整合起来。但大部分文章只是SDL推出的一次,我想知道这是可行的迅速3?如果没有,我需要一个桥头。 – taymedee 2016-11-15 15:58:32

+0

它不工作。 :( – Oktaheta 2016-11-16 13:53:17

相关问题