Ios 当我使用键盘向上移动包含的视图时,UIScrollview会丢失其顶部内容

Ios 当我使用键盘向上移动包含的视图时,UIScrollview会丢失其顶部内容,ios,objective-c,uiview,uiscrollview,keyboard,Ios,Objective C,Uiview,Uiscrollview,Keyboard,过去几周来,我一直在努力解决这个问题。当键盘出现时,我向上移动视图控制器中包含的整个视图。一旦我这样做了,视图中包含的scrollview的顶部就变得不可访问。这就像屏幕的顶部切断了我的滚动视图的顶部一样。有办法解决这个问题吗 //Move the keyboard when you select a textfield. -(void)keyboardWillShow:(NSNotification*)notification{ CGSize keyboardSize = [[[notifi

过去几周来,我一直在努力解决这个问题。当键盘出现时,我向上移动视图控制器中包含的整个视图。一旦我这样做了,视图中包含的scrollview的顶部就变得不可访问。这就像屏幕的顶部切断了我的滚动视图的顶部一样。有办法解决这个问题吗

//Move the keyboard when you select a textfield.
-(void)keyboardWillShow:(NSNotification*)notification{

CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

CGRect viewRect = self.view.frame;
viewRect.origin.y = -215;

[UIView animateWithDuration:0.3f animations:^ {
    self.view.frame = viewRect;
    }];
scrollBounces = YES;
scrollView.contentOffset = CGPointZero;
}
这就是我对包含scrollview的视图所做的全部操作。

您也可以为scrollview设置contentInset和ScrollIndications设置:

[scrollView setContentInset:UIEdgeInsetsMake(215, 0, 0, 0)];

[scrollView setScrollIndicatorInsets:UIEdgeInsetsMake(215, 0, 0, 0)];

在键盘上写下下面三行

UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kKeyboardHeightValue, 0.0);
self.mDisplayedScrollview_.contentInset = contentInsets;
self.mDisplayedScrollview_.scrollIndicatorInsets = contentInsets;

在键盘上写下以下三行

UIEdgeInsets contentInsets = UIEdgeInsetsZero;
self.mDisplayedScrollview_.contentInset = contentInsets;
self.mDisplayedScrollview_.scrollIndicatorInsets = contentInsets;

当键盘在那里时,你能添加屏幕截图吗?也可以添加你需要的屏幕截图谢谢,我不敢相信我忽略了设置插图!你是救命恩人!这种方法在iOS 7上适用,但在iOS 8上不适用。你知道怎么了吗?我需要强制更新布局吗?