我正在使用代码到文本字段,它工作正常(也与cocos2d),但我不明白为什么键盘打开时,我启动应用程序?我希望它像那样:
任何帮助都可以做到这一点。
我的代码:(setText
)
init
-(void)setText
{
myText = [[UITextField alloc] initWithFrame:CGRectMake(100, 120, 200, 90)];
myText.transform = CGAffineTransformMakeRotation( M_PI / 2.0 );
[myText setDelegate:self];
[myText setText:@"yes"];
[myText setTextColor: [UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]];
[[[[CCDirector sharedDirector] openGLView] window] addSubview:myText];
[myText becomeFirstResponder];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[myText resignFirstResponder];
return YES;
}
-(void)textFieldDidEndEditing: (UITextField *)textField {
if(textField == myText)
{
[myText endEditing:YES];
[myText removeFromSuperview];
NSString *result = myText.text;
NSLog(@"%@",result);
}
else
{
NSLog(@"textField did not match myText");
}
}
答案 0 :(得分:1)
因为你把这个:
[myText becomeFirstResponder]
取出它,当你的应用加载时它不应该带键盘。