uiscrollview textured background is compressed after frame animation
I have a UIScrollView which is resized when the keyboard is presented (to stay above the keyboard as it slides in from the bottom.) To make the animation work right I have to specify UIAnimation开发者_如何学GoOptionBeginFromCurrentState. If I don't specify this I get weird effects during the animation and I can see the view behind the UIScrollView peek through. Here's the animation routine:
- (void) onKeyboardWillShow: (NSNotification*) n
{
// get the keyboard rect
CGRect rKeyboard; NSValue* v;
v = [n.userInfo objectForKey: UIKeyboardFrameEndUserInfoKey];
[v getValue: &rKeyboard];
rKeyboard = [self.view convertRect: rKeyboard fromView: nil];
// get the keyboard animation duration, animation curve
v = [n.userInfo objectForKey: UIKeyboardAnimationDurationUserInfoKey];
double keyboardAnimationDuration;
[v getValue: &keyboardAnimationDuration];
v = [n.userInfo objectForKey: UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve keyboardAnimationCurve;
[v getValue: &keyboardAnimationCurve];
// animate
[UIView animateWithDuration: keyboardAnimationDuration
delay: 0
options: UIViewAnimationOptionBeginFromCurrentState | keyboardAnimationCurve
animations: ^{
CGRect f = _clientAreaView.frame;
f.size.height = rKeyboard.origin.y - f.origin.y;
_clientAreaView.frame = f;
}
completion: ^(BOOL finished) {
}];
}
The problem is the UIScrollView backgroundColor, which is set to scrollViewTexturedBackgroundColor. After the animation the textured background is compressed (with minor artifacts showing). If I animate it all back to the original size it returns to normal.
How to make it so the background either doesn't resize with the animation, or at least have the background 'pop' back to an uncompressed look post animation? I tried setting the bg color in the completion routine (to white, then back to scrollViewTexturedBackgroundColor, but this didn't work, and I dont really understand why.)
I think your problem might be related to setting the value of UIKeyboardAnimationCurveUserInfoKey
(which is a UIViewAnimationCurve
and not a UIViewAnimationOption
) along with UIViewAnimationOptionBeginFromCurrentState
(which is supposed to capture the current state and modify it).
Animating the frame of UIScrollView
(and UITableView
) is buggy on iOS, therefore you should animate the contentInset
and scrollIndicatorInsets
properties as well as the contentOffset
if you need to reposition your views (e.g. moving a text field up).
Just add the height of the keyboard to the bottom part of the insets and calculate if you need to scroll up or down.
精彩评论