我在iOS上看到的一些SDL演示,所有渲染都发生在SDL_Window
而不是UIWindow
内。但是,由于大多数iOS应用程序都是基于一个UIWindow建模的。我想将iOS与SDL集成,并在UIViewController的视图中嵌入SDL的窗口(或SDL的视图)。这是如何完成的?
我发布了我的问题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
答案 0 :(得分:1)
问题是由于我的代码引用了错误的变量。应该替换embedView中的以下行:
[self.window.rootViewController.view addSubview:vw];
与
[myWindow.rootViewController.view addSubview:vw];