标签:des style blog io color os ar for sp
最近做着CCEditBox 时,发现点击后,里面的文字没有适配的
今天比较,所以解决一下这个问题
找到CCEditBox点击时响应的函数是 CCEditBoxImplIOS::openKeyboard
我们可以看看这个函数写了什么:
-(void) openKeyboard
{
[[EAGLView sharedEGLView] addSubview:textField_]; // 添加 作为 subView
[textField_ becomeFirstResponder];
}
完全没有对textField_ 进行处理,于是我对这个textField_进行了处理
由于对objective-c 的类的属性不熟悉,所以问了一下度娘,这样也不是办法!
于是想到,textField_肯定要初始化的,所以在 CCEditBoxImplIOS 这个源文件里,找到了下面这段代码
-(id) initWithFrame: (CGRect) frameRect editBox: (void*) editBox { self = [super init]; do { if (self == nil) break; editState_ = NO; self.textField = [[[CustomUITextField alloc] initWithFrame: frameRect] autorelease]; // 初始化frame if (!textField_) break; [textField_ setTextColor:[UIColor whiteColor]]; textField_.font = [UIFont systemFontOfSize:frameRect.size.height*2/3]; // 初始化font textField_.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; textField_.backgroundColor = [UIColor clearColor]; textField_.borderStyle = UITextBorderStyleNone; textField_.delegate = self; textField_.hidden = true; textField_.returnKeyType = UIReturnKeyDefault; [textField_ addTarget:self action:@selector(textChanged) forControlEvents:UIControlEventEditingChanged]; self.editBox = editBox; return self; }while(0); return nil; }
参照着下面三行代码:
self.textField = [[[CustomUITextField alloc] initWithFrame: frameRect] autorelease]; if (!textField_) break; [textField_ setTextColor:[UIColor whiteColor]]; textField_.font = [UIFont systemFontOfSize:frameRect.size.height*2/3];
添加了如下代码
-(void) openKeyboard { /******* *** add by author: zero *** description : CCEditBox ios 适配问题 *******/ CGFloat scale = [[EAGLView sharedEGLView] contentScaleFactor]; CGRect rect = [textField_ frame]; textField_.font = [UIFont systemFontOfSize:[textField_ frame].size.height * scale*2/3]; [textField_ setFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width * scale, rect.size.height * scale)]; [[EAGLView sharedEGLView] addSubview:textField_]; [textField_ becomeFirstResponder]; }
最后得到完美的成果!
cocos2dx 2.2.5 CCEditBox IOS 适配问题
标签:des style blog io color os ar for sp
原文地址:http://www.cnblogs.com/panazhiyong/p/4067464.html