UIButton出现在错误的层 - Cocos2D

时间:2013-03-02 03:10:02

标签: objective-c cocos2d-iphone uibutton apple-push-notifications

我在游戏中使用appoxee消息服务..

我的第一层是“StartUpLayer”StartUpLayer等待StageLayer完成加载..然后转到我的UIButton声明的舞台层..

然而,我的UIButton第一次出现在StartUpLater中并一直待到发布之前..我该如何解决这个问题?感谢..

的AppDelegate

- (void) AppoxeeNeedsToUpdateBadge:(int)badgeNum hasNumberChanged:(BOOL)hasNumberChanged
{

    if(badgeNum > 0)
    {
        badgeText = [NSString stringWithFormat:@"%d",badgeNum];
    }

    StageLayer *stgLayer = [[StageLayer alloc] init];


    [[AppoxeeManager sharedManager] addBadgeToView:stgLayer.AppoxeeButton  badgeText:badgeText badgeLocation:CGPointMake(0,0) shouldFlashBadge:hasNumberChanged]; 

    [UIApplication sharedApplication].applicationIconBadgeNumber = badgeNum;
}

Stage Layer init

AppoxeeButton = [[UIButton alloc] initWithFrame:CGRectMake(100,100,100,100)];
            [AppoxeeButton setBackgroundImage:[UIImage imageNamed:@"messages-button.png"] forState:UIControlStateNormal];
            [AppoxeeButton setTitle:@"" forState:UIControlStateNormal];
            [AppoxeeButton addTarget:self action:@selector(inboxPressed) forControlEvents:UIControlEventTouchUpInside];
            [[[CCDirector sharedDirector] openGLView] addSubview:AppoxeeButton];

1 个答案:

答案 0 :(得分:0)

AproxeeButton apeears不在startUpLayer中,但它出现在CCDirector openGL视图中。这就是为什么它总是位于所有cocos2d节点和层之上。

关于为什么在startUpLayer

时显示它的问题的答案 在AppDelegate中调用

StageLayer *stgLayer = [[StageLayer alloc] init];,因此在应用程序启动后会显示AproxeeButton