Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 带键盘的UIScrollview:内容偏移问题_Ios_Objective C_Ios7_Uiscrollview_Autolayout - Fatal编程技术网

Ios 带键盘的UIScrollview:内容偏移问题

Ios 带键盘的UIScrollview:内容偏移问题,ios,objective-c,ios7,uiscrollview,autolayout,Ios,Objective C,Ios7,Uiscrollview,Autolayout,我想滚动scrollview的内容,下面是代码。问题是scrollview的contentOffset,即使我以编程方式更改它,也不会更改 // Called when the UIKeyboardWillShowNotification is sent. - (void)keyboardWillShow:(NSNotification*)aNotification { NSDictionary* info = [aNotification userInfo]; CGSize k

我想滚动scrollview的内容,下面是代码。问题是scrollview的
contentOffset
,即使我以编程方式更改它,也不会更改

// Called when the UIKeyboardWillShowNotification is sent.
- (void)keyboardWillShow:(NSNotification*)aNotification
{
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    NSTimeInterval animationDuration;
    [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];

    // If active text field is hidden behind keyboard then scroll it so it's visible.
    CGRect aRect = self.contentView.frame;
    aRect.size.height -= kbSize.height;

    // Change contentInset
    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height - TABBAR_HEIGHT, 0.0);
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;

    [UIView animateWithDuration:animationDuration delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        // scorll the contentView accoring to which textField is selected.
        CGFloat yvalue = - ((self.scrollView.frame.size.height - ((self.editedRealName.isEditing)? self.editedRealName.frame.origin.y :self.birthdate.frame.origin.y)) - self.scrollView.contentOffset.y - (kbSize.height - TABBAR_HEIGHT)) + 35;
        [scrollView setContentOffset:CGPointMake(0, yvalue) animated:YES];
    } completion:nil];   

    // printing contentOffset at this point prints older value.i.e.(0,0).
}

// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
    // Here, when print contentOffset value then it prints modified value.

    UIEdgeInsets contentInsets = UIEdgeInsetsZero;
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;

    [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        //scroll the contentView back to top.
        self.scrollView.ContentOffset = CGPointMake(0, 0);
    } completion:nil];

}
更改
contentInset
会向上滚动内容,文本字段可见。但我希望它再滚动10点,这样文本字段和键盘之间就有10点的间距。与上述代码相比,它们之间的差值为0分


我使用自动布局。我不知道这是否与我的问题有关。

简单地将scrollview的底部插入增加10难道不起作用吗?UIEdgeInsets contentInsets=UIEdgeInsetsMake(0.0,0.0,kbSize.height-TABBAR_height+10,0.0);-从软件工程的角度来看,需要进行一些微调(考虑横向模式等,可能会有所不同…@Lepidopteron将
contentInset
bottom增加10将显示scrollview的superview,在scrollview和键盘之间的10点间隙中。对不起,我以为你的文本字段在uiscrollview中。。。如果文本字段不在此滚动视图中,为什么还要向上滚动/更改其插入内容?