【发布时间】:2011-09-24 04:10:24
【问题描述】:
我有一个 UIScrollView,它在出现键盘时会调整大小(在键盘从底部滑入时保持在键盘上方。)为了使动画正常工作,我必须指定 UIAnimationOptionBeginFromCurrentState。如果我不指定这一点,我会在动画期间得到奇怪的效果,并且我可以看到 UIScrollView 背后的视图。这是动画例程:
- (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) {
}];
}
问题是UIScrollView backgroundColor,设置为scrollViewTexturedBackgroundColor。动画结束后,纹理背景被压缩(显示轻微伪影)。如果我将它全部设置为原始大小,它就会恢复正常。
如何使背景不随动画调整大小,或者至少让背景“弹出”回到未压缩的后动画外观?我尝试在完成例程中设置 bg 颜色(设置为白色,然后返回到 scrollViewTexturedBackgroundColor,但这不起作用,我真的不明白为什么。)
【问题讨论】:
标签: iphone ios ipad uiscrollview uiviewanimation