这段代码在堆栈溢出和一般互联网上经常看到。它用于调整文本视图的大小,以便您可以看到所有内容。它对我来说工作正常然后停止工作。(即一旦框架改变并且可以滚动,现在它什么都不做。)有没有人对为什么停止工作以及如何修复它有任何建议。
我已经在多个地方(使用 NSLog)确认它确实被调用了。
-(void)moveTextViewForKeyboard:(NSNotification*)aNotification up:(BOOL)up {
NSDictionary* userInfo = [aNotification userInfo];
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
CGRect keyboardEndFrame;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:animationCurve];
CGRect newFrame = indexCardText.frame;
CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil];
keyboardFrame.size.height -= self.tabBarController.tabBar.frame.size.height;
newFrame.size.height -= keyboardFrame.size.height * (up?1:-1);
indexCardText.frame = newFrame;
[UIView commitAnimations];
}
谢谢!