views:

46

answers:

1

The following function is a method of a class called TitleOverlay - which is a transparent overlay with a textView.

The function shows the overlay by animating its alpha, and in parallel uses the animationWillStart property of the animation to show the keyboard.

On 3G phones, the first time this function is called, there is some lag before the keyboard shows. In fact, I think the animation to show the overlay and show the keyboard are being serialized. I tried setting the length of the overlay alpha animation to various lengths, and the keyboad always shows after the animation completes.

Basically, the first time, there is lag. On all subsequent times, the keyboard and the overlay animations occur in parallel, and it looks nice.

WHat can I do to fix this?

- (void) showOverlay {

  [[self superview] bringSubviewToFront:self];

  NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
  [nc addObserver:self 
         selector:@selector(keyboardWillShow:) 
            name:UIKeyboardWillShowNotification 
          object:nil];
  [nc addObserver:self 
         selector:@selector(keyboardWillHide:) 
             name:UIKeyboardWillHideNotification 
           object:nil];

  [UIView beginAnimations:nil context: nil];
  [UIView setAnimationDuration: .5];
  [UIView setAnimationDelegate:titleField];
  [UIView setAnimationWillStartSelector:@selector(becomeFirstResponder)];
  self.whiteBlock.alpha = 1;
  [UIView commitAnimations];

} 
+1  A: 

The lag when displaying a keyboard for the first time in an iPhone application is a known issue. There is a hack to work around this, as pointed out in that question.

Brad Larson
Hey Brad, thanks a lot! I don't suppose you know the answer of this one too, from my colleague: http://stackoverflow.com/questions/2137521/iphone-unit-test-linking-problem-cant-find-devtoolsbundleinjection-framework
Andrew Johnson