• <bdo id='PU0i6'></bdo><ul id='PU0i6'></ul>

    <tfoot id='PU0i6'></tfoot>

    1. <small id='PU0i6'></small><noframes id='PU0i6'>

    2. <i id='PU0i6'><tr id='PU0i6'><dt id='PU0i6'><q id='PU0i6'><span id='PU0i6'><b id='PU0i6'><form id='PU0i6'><ins id='PU0i6'></ins><ul id='PU0i6'></ul><sub id='PU0i6'></sub></form><legend id='PU0i6'></legend><bdo id='PU0i6'><pre id='PU0i6'><center id='PU0i6'></center></pre></bdo></b><th id='PU0i6'></th></span></q></dt></tr></i><div id='PU0i6'><tfoot id='PU0i6'></tfoot><dl id='PU0i6'><fieldset id='PU0i6'></fieldset></dl></div>
      <legend id='PU0i6'><style id='PU0i6'><dir id='PU0i6'><q id='PU0i6'></q></dir></style></legend>

      1. 以编程方式调用 textFieldShouldReturn

        时间:2024-08-12

        <small id='hq9yS'></small><noframes id='hq9yS'>

            <bdo id='hq9yS'></bdo><ul id='hq9yS'></ul>
            <legend id='hq9yS'><style id='hq9yS'><dir id='hq9yS'><q id='hq9yS'></q></dir></style></legend>
            • <tfoot id='hq9yS'></tfoot>

              <i id='hq9yS'><tr id='hq9yS'><dt id='hq9yS'><q id='hq9yS'><span id='hq9yS'><b id='hq9yS'><form id='hq9yS'><ins id='hq9yS'></ins><ul id='hq9yS'></ul><sub id='hq9yS'></sub></form><legend id='hq9yS'></legend><bdo id='hq9yS'><pre id='hq9yS'><center id='hq9yS'></center></pre></bdo></b><th id='hq9yS'></th></span></q></dt></tr></i><div id='hq9yS'><tfoot id='hq9yS'></tfoot><dl id='hq9yS'><fieldset id='hq9yS'></fieldset></dl></div>

                  <tbody id='hq9yS'></tbody>
                  本文介绍了以编程方式调用 textFieldShouldReturn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当前项目运行在cocos2d v2下.

                  The current project runs under cocos2d v2.

                  我有一个简单的 UITextField 添加到 CCLayer.

                  I have a simple UITextField added to a CCLayer.

                  每当用户触摸文本字段时,就会出现一个键盘.

                  Whenever, the user touch the textField, a keyboard appears.

                  然后当用户触摸返回"按钮时,键盘消失并清除输入.

                  Then when the user touch the "return" button, the keyboard disappear and clears the input.

                  我试图做的是当用户触摸 UITextField 之外的任何地方时做同样的事情.

                  What I tried to do is to make the same thing when the user touches anywhere outside the UITextField.

                  我确实找到了一种方法并且它有效:

                  I did find a method and it works :

                  - (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
                  {
                      UITouch* touch = [touches anyObject];
                      if(touch.view.tag != kTAGTextField){
                          [[[[CCDirector sharedDirector] view] viewWithTag:kTAGTextField] resignFirstResponder];
                      }
                  }
                  

                  但是,这个方法并没有调用函数:

                  However, this method doesn't call the function :

                  - (BOOL)textFieldShouldReturn:(UITextField *)textField
                  

                  我用这个函数做一些计算并清除输入.因此,当文本字段为resignFirstResponder"时,我希望 ccTouchesBegan 输入此 textFieldShouldReturn.

                  I use this function to do some calculation and clear the input. Therefore, I would like ccTouchesBegan to enter this textFieldShouldReturn when the textfield is "resignFirstResponder".

                  推荐答案

                  来自 苹果文档:

                  textFieldShouldReturn:询问委托文本字段是否应处理按下返回按钮.

                  textFieldShouldReturn: Asks the delegate if the text field should process the pressing of the return button.

                  所以它只有在用户点击返回按钮时才会被调用.

                  So it is only called when the user taps the return button.

                  我宁愿创建一个用于计算和输入清除的方法,并在需要时调用该方法.示例:

                  I would rather create a method for the calculation and input clearing, and call that method whenever you want it to be called. Example:

                  - (void)calculateAndClearInput {
                      // Do some calculations and clear the input.
                  }
                  
                  - (BOOL)textFieldShouldReturn:(UITextField *)textField {
                      // Call your calculation and clearing method.
                      [self calculateAndClearInput];
                      return YES;
                  }
                  
                  - (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
                      UITouch* touch = [touches anyObject];
                      if (touch.view.tag != kTAGTextField) {
                          [[[[CCDirector sharedDirector] view] viewWithTag:kTAGTextField] resignFirstResponder];
                          // Call it here as well.
                          [self calculateAndClearInput];
                      }
                  }
                  

                  这篇关于以编程方式调用 textFieldShouldReturn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 cocos2d ios 中播放 BGM 并知道当前播放时间? 下一篇:使用openGL和cocos2D绘制大量线条的最佳方法是什么?

                  相关文章

                  <tfoot id='lht8P'></tfoot>
                  • <bdo id='lht8P'></bdo><ul id='lht8P'></ul>
                  1. <small id='lht8P'></small><noframes id='lht8P'>

                      <i id='lht8P'><tr id='lht8P'><dt id='lht8P'><q id='lht8P'><span id='lht8P'><b id='lht8P'><form id='lht8P'><ins id='lht8P'></ins><ul id='lht8P'></ul><sub id='lht8P'></sub></form><legend id='lht8P'></legend><bdo id='lht8P'><pre id='lht8P'><center id='lht8P'></center></pre></bdo></b><th id='lht8P'></th></span></q></dt></tr></i><div id='lht8P'><tfoot id='lht8P'></tfoot><dl id='lht8P'><fieldset id='lht8P'></fieldset></dl></div>
                      <legend id='lht8P'><style id='lht8P'><dir id='lht8P'><q id='lht8P'></q></dir></style></legend>