popviewcontroller重置scrollview contentoffset

时间:2012-05-12 14:37:40

标签: iphone objective-c ios

我有一个内置UITextfield的scrollview。当键盘出现时,我使用setContentOffset:animated:滚动滚动视图。但是,当按下“返回”按钮到popViewControllerAnimated:时,滚动视图会向下滚动。我希望弹出视图时滚动位置保持不变。知道如何让它正常工作吗?

谢谢!

// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{

...

// If active text field is hidden by keyboard, scroll it so it's visible
CGRect aRect = CGRectMake(0, 0, 320, 460-44-215);
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) {
    CGPoint scrollPoint = CGPointMake(0.0, activeField.frame.origin.y-80);
    [sv setContentOffset:scrollPoint animated:YES];
}
}

0 个答案:

没有答案