2010-12-31 19 views

答えて

1

上記のように、クラスはUIViewと呼ばれます。新しいビューを作成するのはとても簡単です。このコードスニペットを見てください。

-(void)youButtonAction:(id)sender { 
    //This method is executed as soon as you button is pressed. 
    UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)]; 
    [anotherView addSubview:newView]; //Add the newView to another View 
    [newView release]; 
} 

私はあなたがポイントを得たと思う。最初はビューを作成し、別のビューに追加し、最後にそれをリリースする必要があります。 ;-)

サンドロ・マイヤー

+0

イベント処理を記述し、私は彼がcocos2dのシーンではなく、別のビューにビューを追加するために求めていると思います。 – russell

+0

ああ。それは可能です。あなたはそれを説明しました。 :-D –

5

あなたは

UIButton* myButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
myButton.frame = CGRectMake(30, 70,100,38); //set frame for button 

[myButton setTitle:@"subview" forState:UIControlStateNormal]; 
[myButton addTarget:self action:@selector(buttonClicked:)forControlEvents:UIControlEventTouchUpInside]; 

like-ボタンを作成するために持っているか、あなたがボタンとしてCCMenuを使用することができます。その後、

そして機能 -

-(void)buttonClicked:(id)sender 
{ 
     UIView *myview=[[UIView alloc] initWithFrame: CGRectMake(0, 0,320,480)]; 
     myview.backgroundColor=[UIColor redColor]; 
     [[[CCDirector sharedDirector] openGLView] addSubview:myview]; 
     [myview release];     
} 

}

関連する問題