对我来说一切都很好,除了一个案例。当我开始编辑文本字段时,显示键盘:方法被调用,但如果我编辑下一个文本字段而不退出第一个,则不会调用此方法。
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
}
-(void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
testScroll.contentInset = contentInsets;
testScroll.scrollIndicatorInsets = contentInsets;
CGRect aRect = self.view.bounds;
CGPoint activepoint= [active.superview convertPoint:active.frame.origin toView:nil];
if (!CGRectContainsPoint(aRect, activepoint) ) {
CGPoint scrollPoint = CGPointMake(0.0, active.frame.origin.y+active.frame.size.height-kbSize.height+100);// here active is my particular textfields and i an changing it in begin editing method.
[testScroll setContentOffset:scrollPoint animated:YES];
}
这里我的问题是即使我在两个文本字段之间切换,我的滚动视图必须为特定的偏移量设置。
谢谢你。