Delay Keyboard pop up

Discussion in 'iOS Programming' started by larswik, Dec 21, 2011.

  1. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    I was wondering if there is anyway to delay the keyboard popping up when you click on a UITextView? I have a UITextView at the bottom of the screen. When they user clicks on it The delegate method is called that brings forward the keyboard. I created an animation that moves the UITextView to the top of the screen but the keyboard comes on so quickly that the animation of the textView is not smooth.

    If I could delay the pop up until the animation finishes that would be a great look. Since it is a delegate method that brings forward the keyboard I don't know if I could delay it 1/2 a second. Here is the code

    Code:
    - (void)textViewDidBeginEditing:(UITextView *)textView{
        fadeBlackTimer= [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(fadeToBlack) userInfo:nil repeats:YES];
        NSLog(@"Time for update");
        self.navigationItem.rightBarButtonItem.enabled = YES;
    }
    
    -(void)fadeToBlack{
        fadeToBlackView.alpha += fadeBlack;
        notesTextView.center = CGPointMake(self.view.center.x, self.view.center.y - moveTextView); 
        if (moveTextView < 99) {
            moveTextView += 2;
        }
        NSLog(@"move: %d",moveTextView);
        if (fadeToBlackView.alpha > 1.4) { // 1.4 allows extra time for animation of TextView.
            [fadeBlackTimer invalidate];
            fadeToBlackView.alpha = 1.0;
            moveTextView = 2;
        }
    
    }
     
  2. ppilone macrumors 6502

    Joined:
    Jan 20, 2008
    #2
    If you're just looking to adjust the text view for the keyboard I'd suggest registering for keyboard notifications as opposed to using the text view's delegate.

    Specifically:

    UIKeyboardWillShowNotification
    UIKeyboardDidShowNotification
    UIKeyboardWillHideNotification
    UIKeyboardDidHideNotification

    Check the UIWindow class reference for detailed descriptions of the notifications.
     
  3. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #3
    This is why I like asking questions here, I didn't even know those existed. I will read up on those tonight. Thank you!
     
  4. ArtOfWarfare macrumors G3

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    Those notifications are also really useful because they can also tell you what the frame of the keyboard is going to be. Thus you can make sure your text field's frame won't be covered up, even if the user is on a device where the keyboard is a different size (say iPhone vs. iPad,) or Apple decides to modify the keyboard in the future (maybe they'll finally add numbers above the letters so you can access those without having to hit the number key each time? Wishful thinking, but, still, write your code properly now so you don't have to rewrite it later.)
     
  5. dejo, Dec 21, 2011
    Last edited: Dec 21, 2011

    dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Please, no. The keyboard already takes up plenty of scarce screen real-estate on the iPhone / iPod touch.
     
  6. MattInOz macrumors 68030

    MattInOz

    Joined:
    Jan 19, 2006
    Location:
    Sydney
    #6
    You forgot to mention Accessory Views.

    Apple doesn't need to change the base keyboards at all. You can use an accessory view to add the numbers if you really want them. As they are tied to the input field you only need them when they make sense, but that means they are the thing most likely to change the area of keyboard during run time and change how much you need to scroll to make the input visible.
     
  7. ppilone macrumors 6502

    Joined:
    Jan 20, 2008
    #7
    IIRC the Japanese keyboard is slightly taller than English keyboards. A good example of why you should use the keyboard notifications.
     
  8. ArtOfWarfare macrumors G3

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #8
    This wouldn't add the number row to built-in apps like Notes or iMessages.

    Make the screen 4" and add in a row of numbers, roughly half as tall as the letter keys all are.

    At least on the iPad they wouldn't take up too much space... just look at the HP TouchPad... it includes a number row without taking up too much screen space. (Not that the screen space is worth anything. The built in apps suck and apps on their store aren't much better.)
     
  9. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #9
    Also have u tried using ANimation blocks, for smoothing out the transition? ;)
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    Why not just make all the keys half as tall? Or better yet, add a hardware keyboard to the iPhone. </sarcasm>
     
  11. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #11
    I have not tried Animation Blocks. I have heard of Blocks in passing but don't know what they are. It sounds like grouped code or something. This might be a good weekend project to learn something new.
     
  12. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #12
    You have worked with ANimations?
    (in style of)
    Code:
    [UIView viewWithAnimations:blallaal moreblallala];
    
    Just look for animation blocks on google :)
     

Share This Page