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 t开发者_如何学Pythono 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];
}
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.
精彩评论