当进入UITextfield时,在iPhone4S中滚动视图会下降

时间:2015-03-20 10:20:10

标签: ios objective-c iphone uiscrollview size-classes

我遇到了有关iPhone4S的textfield问题。我被带到了一些文本域,并为UITextFields编写了以下方法

    - (BOOL)textFieldShouldReturn:(UITextField *)textField{
    if(textField==txtAmount){
        [txtAmount resignFirstResponder];
        [txtVat becomeFirstResponder];
        if (IS_IPHONE_5) {
            [scrollObj setContentOffset:CGPointMake(0, 155) animated:YES];
        }
        else if (IS_IPHONE_6){
            [scrollObj setContentOffset:CGPointMake(0, 150) animated:YES];
        }
        else if (IS_IPHONE_6P){
            [scrollObj setContentOffset:CGPointMake(0, 150) animated:YES];
        }
        else{
            [scrollObj setContentOffset:CGPointMake(0,250) animated:YES];
        }
    }
    else if (textField==txtVat) {
        [txtVat resignFirstResponder];
        [txtShope becomeFirstResponder];

        if (IS_IPHONE_5) {
            [scrollObj setContentOffset:CGPointMake(0, 212) animated:YES];
        }
        else if (IS_IPHONE_6){
            [scrollObj setContentOffset:CGPointMake(0, 210) animated:YES];
        }
        else if (IS_IPHONE_6P){
             [scrollObj setContentOffset:CGPointMake(0, 205) animated:YES];
        }
        else{
           [scrollObj setContentOffset:CGPointMake(0, 330) animated:YES];
        }
    }
    else if (textField==txtShope) {
        [txtShope resignFirstResponder];
        [txtProductName becomeFirstResponder];

        if (IS_IPHONE_5) {
            [scrollObj setContentOffset:CGPointMake(0, 295) animated:YES];
        }
        else if (IS_IPHONE_6){
            [scrollObj setContentOffset:CGPointMake(0, 295) animated:YES];
        }
        else if (IS_IPHONE_6P){
            [scrollObj setContentOffset:CGPointMake(0, 290) animated:YES];
        }
        else{
            [scrollObj setContentOffset:CGPointMake(0, 400) animated:YES];
        }
    }
    else{
        [textField resignFirstResponder];
        [scrollObj setContentOffset:CGPointMake(0, 0) animated:YES];
    }
    return YES;
}


-(void)textFieldDidBeginEditing:(UITextField *)textField {
    if (textField==txtAmount) {
        if (IS_IPHONE_4_OR_LESS) {
            [scrollObj setContentOffset:CGPointMake(0, 65) animated:YES];
        }
    }
    else if (textField==txtVat ) {
        if (IS_IPHONE_5) {
            [scrollObj setContentOffset:CGPointMake(0, 155) animated:YES];
        }
        else if (IS_IPHONE_6){
            [scrollObj setContentOffset:CGPointMake(0, 150) animated:YES];
        }
        else if (IS_IPHONE_6P){
            [scrollObj setContentOffset:CGPointMake(0, 150) animated:YES];
        }
        else{
            [scrollObj setContentOffset:CGPointMake(0, 450) animated:YES];
        }
    }
    else if (textField==txtShope){
        if (IS_IPHONE_5) {
            [scrollObj setContentOffset:CGPointMake(0, 212) animated:YES];
        }
        else if (IS_IPHONE_6){
            [scrollObj setContentOffset:CGPointMake(0, 210) animated:YES];
        }
        else if (IS_IPHONE_6P){
            [scrollObj setContentOffset:CGPointMake(0, 205) animated:YES];
        }
        else{
            [scrollObj setContentOffset:CGPointMake(0, 650) animated:YES];
        }
    }
    else if (textField==txtProductName){
        if (IS_IPHONE_5) {
            [scrollObj setContentOffset:CGPointMake(0, 295) animated:YES];
        }
        else if (IS_IPHONE_6){
            [scrollObj setContentOffset:CGPointMake(0, 295) animated:YES];
        }
        else if (IS_IPHONE_6P){
            [scrollObj setContentOffset:CGPointMake(0, 290) animated:YES];
        }
        else{
            [scrollObj setContentOffset:CGPointMake(0, 400) animated:YES];
        }

    }
}

它完全适用于iPhone5,iPhone6,iPhone6P但不适用于iPhone4S 当点击txtAmount时,它的Fist表现正确,它将contentofset设置为完美,然后突然下降scrollview。我找不到解决方案。

if (textField==txtAmount) {
        if (IS_IPHONE_4_OR_LESS) {
            [scrollObj setContentOffset:CGPointMake(0, 65) animated:YES];
        }
    }

上面的代码设置了scrollview集的内容,但之后它会下降。谁能帮我?它在其他设备上工作但不在iPhone4上工作。我在XIB中使用了Sizeclass和Autoresize。而且我没有在任何其他方法中设置scrollof的内容。

提前致谢...

0 个答案:

没有答案