UIScrollView - 向上滚动但不向下滚动

时间:2014-09-28 05:14:25

标签: ios objective-c uiscrollview

如何将此UIScrollView设置为专注于特定点上的Selected UITextfield。我想在键盘上方的文本字段,我希望能够向上滚动而不是向下滚动。我的代码工作除了uiscrollview只允许我向下滚动而不是向上。任何帮助都会很棒,谢谢。

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.4];
        //set Y according to keyBoard height

        [self->mainScroll2 setFrame:CGRectMake(0.0,-70.0,320.0,580.0)];
        [self->mainScroll2 setContentSize:CGSizeMake(320,780)];

        [UIView commitAnimations];

}

1 个答案:

答案 0 :(得分:0)

根据我对您案例的理解,您在UIScrollView中有一个UITextfield,对吧? 如果是这种情况,我建议您使用contentInset的属性UIScrollVIew“向上滚动” 例如:

float yourKeyboardHeight = 70.0;//since you are trying to change the scrollview's y to -70    
self.mainScroll2.contentInset = UIEdgeInsetsMake(0,0,yourKeyboardHeight,0);

这告诉UIScrollView在contentView后面创建一个占位符。在这段代码中,属性有四个参数,就像UIEdgeInsetsMake(top, left, bottom, right)我刚刚在视图中添加了一个底部插图,这样就可以使内容向上移动70.0 希望这可能会有所帮助