2013-11-26 15 views
0

我是Corona Enterprise和Objective C的新手,但是我已经有了我想在没有Corona的情况下在XCode上工作的内容。现在,当我试图将它放入一个Corona项目中时,它并不能很好地工作......如何使用Corona Enterprise在iOS上本地更改窗口颜色?

我将代码缩小到了最低限度,只将窗口颜色设置为红色。发生了什么事情是窗口变成了红色,但在XCode模拟器上只有不到一秒钟的时间。在那之后,就变成黑色......再次

这里是我的AppDelegate代码:

showLoading(lua_State *L) 
{ 
    void *platformContext = CoronaLuaGetContext(L); // lua_touserdata(L, lua_upvalueindex(1)); 
    id<CoronaRuntime> runtime = (id<CoronaRuntime>)platformContext; 
    runtime.appWindow.backgroundColor = [UIColor redColor]; 

    // Return 0 since this Lua function does not return any values. 
    return 0; 
} 

- (void)willLoadMain:(id<CoronaRuntime>)runtime 
{ 
    lua_State *L = runtime.L; 

    const luaL_Reg kFunctions[] = 
    { 
     "showLoading", showLoading, 

     NULL, NULL 
    }; 

    luaL_register(L, "window", kFunctions); 
    lua_pop(L, 1); 
} 

而且在main.lua我只叫:

window.showLoading() 

我在做什么错?我只需要了解这一点就可以在窗口中显示我想要的内容。我试着用runtime.appViewController.view.backgroundColor但屏幕仍然显示一个黑色,而不是红色...

回答

0

好吧,我发现什么是错,而我在等待一个答案。下面是新的代码,里面的AppDelegate:

showLoading(lua_State *L) 
{ 
    void *platformContext = CoronaLuaGetContext(L); 
    id<CoronaRuntime> runtime = (id<CoronaRuntime>)platformContext; 
    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    if (!runtime.appViewController.view) 
     runtime.appViewController.view=[[UIView alloc] initWithFrame:screenRect]; 
    runtime.appViewController.view.backgroundColor = [UIColor redColor]; 

    // Return 0 since this Lua function does not return any values. 
    return 0; 
} 

在开始的时候,我还以为runtime.appViewController.view已初始化。现在我看到它不是。但是,如果我将任何元素添加到main.lua,它将被初始化,因此,如果它仍然nil需要if来初始化它。