1:確保您CCNode
包含UITextFieldDelegate
:
@interface MyLayer : CCLayer <UITextFieldDelegate>
2:初始化給出UITextField按通常:
UITextField *nameField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, fieldWidth, fieldHeight)];
nameField.textAlignment = NSTextAlignmentCenter;
nameField.font = [UIFont fontWithName:kFontName size:24];
nameField.text = @"Enter Name";
nameField.delegate = self;
nameField.backgroundColor = [UIColor grayColor];
nameField.textColor = [UIColor whiteColor];
nameField.autocorrectionType = UITextAutocorrectionTypeNo;
3:字段添加到CCDirector
視圖:
[[[CCDirector sharedDirector] view] addSubview:nameField];
4:實現UITextField
代表在CCNode
:
- (BOOL)textFieldShouldReturn:(UITextField*)textField
- (void)textFieldDidBeginEditing:(UITextField *)textField
謝謝。你沒有解決我的問題,但我發現我的錯誤 – user2083364