Search code examples
ioscocos2d-iphone

Screen moves after CCTextField editing start


I'm using cocos2d 3.0 RC4. When textField in CCTextField receive becomeFirstResponder screen moves down even though there is no need for it. I think this animation purpose is to show the text field if it's covered by keyboard. But I get this animation event if text field is on top and there is plenty of space for keyboard. Is it possible to disable such animation?


Solution

  • Thanks to Macgeo's suggestion I made the following edit to the CCTextField class:

    Add a property in the header:

    @property (nonatomic,assign) BOOL movesViewOnFocus;
    

    Then edit the implementation like so:

    - (void) focusOnTextField
    {
        if (!self.movesViewOnFocus) {
            return;
        }
    

    And:

    - (void) endFocusingOnTextField
    {
        if (!self.movesViewOnFocus) {
            return;
        }
    

    This is a 30 second hack and I have not tested it more than one or two times. But by default it would disable the move on focus. Of course it wouldn't work when turning it on if the textfield is already selected etc but at least it's a start. I'll suggest it to the Cocos2D devs.