Ios 选中UITextField时向上移动UIScrollView

Ios 选中UITextField时向上移动UIScrollView,ios,objective-c,uiscrollview,uitextfield,Ios,Objective C,Uiscrollview,Uitextfield,指定给UIScrollView的子视图。选择UITextField时,UIScrollView应向上移动。我尝试了下面的代码,但它不工作 - (void)textFieldDidBeginEditing:(UITextField *)textField { if( textField == citytextfield) { [UIView beginAnimations:nil context:NULL]; [UIView setAnimatio

指定给UIScrollView的子视图。选择UITextField时,UIScrollView应向上移动。我尝试了下面的代码,但它不工作

- (void)textFieldDidBeginEditing:(UITextField *)textField
{

    if( textField == citytextfield)
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.4];
        //set Y according to keyBoard height
        [_scrolling setFrame:CGRectMake(0.0,-220.0,320.0,460.0)];

        [UIView commitAnimations];
    }



}

- (void)textFieldDidEndEditing:(UITextField *)textField {

    [textField resignFirstResponder];
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    [_scrolling setFrame:CGRectMake(0.0,0.0,320.0,460.0)];
    [UIView commitAnimations];
}

使用
UIScrollView的
setContentOffset
方法使其向上滚动,您需要将值
50
更改为所需的值

[_scrolling setContentOffset:CGPointMake(0,50) animated:YES];

下载tpkeyboardavoidingscrollview。
将scrollview的类名指定给tpkeyboardavoidingscrollview


设置属性并提供与scrollview的连接。
在viewcontroller.h中

#import "TPKeyboardAvoidingScrollView"

然后检查它。

什么是滚动?为什么不使用块动画?你在使用自动布局吗?是否确实将自己设置为文本字段的代理?您的标题显示要滚动滚动视图,但设置帧不会使滚动视图滚动。我为textfield设置了委托。。好的,我会再次检查它,用ScrollView替换视图我在textFieldDidBeginEditing中写了这个,但没有change@iOSDeveloper检查是否已设置textfield委托,并尝试将值50增加到其他值。
#import "TPKeyboardAvoidingScrollView"