2012-10-05 31 views
1

我想在cocos2d使用的UITextField,所以我寫了下面的代碼:如何在Cocos2d中使用UITextField?

// In HelloWorldLayer... 
-(id) init 
{ 
    if(self=[super init]) 
    { 
     CGSize winSize = [[CCDirector sharedDirector] winSize]; 
     UIView *view = [[CCDirector sharedDirector] openGLView]; 

     //  CGRect rect = CGRectMake(60.0, 45.0, 360.0, 25.0); 
     CGPoint pos1 = ccp(60.0, winSize.height - 45.0); 
     CGPoint pos2 = ccp(360.0, 25.0); 

     pos1 = [[CCDirector sharedDirector] convertToUI:pos1]; 
     pos2 = [[CCDirector sharedDirector] convertToUI:pos2]; 

     // UITextField *_tField; it is declared in field 
     _tField = [[UITextField alloc] initWithFrame:CGRectMake(pos1.x, pos1.y, pos2.x, pos2.y)]; 
     _tField.backgroundColor = [UIColor whiteColor]; 
     _tField.borderStyle  = UITextBorderStyleRoundedRect; 
     _tField.returnKeyType = UIReturnKeyDone; 
     _tField.delegate  = self; 

     [view addSubview:_tField]; 
    } 
    return self; 
} 

現在我有這樣的問題: http://serviceapi.nmv.naver.com/flash/convertIframeTag.nhn?vid=F25D1799886DD32FDA54463C2458197E492A&outKey=V1269fde60a3180c7d50216a83d22b478817df9b6060a511adffa16a83d22b478817d&width=720&height=438

我怎樣才能解決這個問題......?

+0

請添加您的錯誤消息 - 不要只是添加一個鏈接,因爲他們變得過時。 –

+0

但我的代碼能夠很好地編譯......錯誤消息是否意味着問題,不僅是編譯錯誤?然後我明白了。 (對不起,但我不擅長英語..) –

回答

1

由問題,你的意思是爲什麼文本沒有被水平寫入? 由於文本實際上是水平寫入的,因此您可能還有其他影響代碼的內容。

+0

感謝您的回答,但我無法猜測是什麼影響我的代碼.. –

+0

你能發佈整個文件嗎 – PenguinSource

+1

你應該看看這個答案 http://stackoverflow.com/questions/693483/textfield-example-in-cocos2d – PenguinSource