当键盘存在工作时,向上移动对话框,除非转动ipad [英] Moving dialog up when keyboard present works except when ipad is turned around

查看:160
本文介绍了当键盘存在工作时,向上移动对话框,除非转动ipad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当键盘出现时,模态对话框会向上移动,当键盘消失时向下移动。

The modal dialog gets moved up when they keyboard appears and moves down when the keyboard disappears.

一切正常,直到我旋转iPad。在除标准之外的任何其他方向,它都不起作用。当iPad转动时,模式对话框会在键盘显示时向下移动,而不是在键盘消失而不是向下时向上移动。

All is fine till I rotate the iPad. In any other orientation except the standard it doesn't work. When the iPad is turned around the modal dialog moves down when the keyboard appears instead of up and up when the keyboard disappears instead of down.

这是我正在使用的代码键盘出现/消失时定位模态对话框。

This is the code I am using to position the modal dialog when keyboard appears/disappears.

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


        self.view.superview.frame = CGRectMake(self.view.superview.frame.origin.x, 140, self.view.superview.frame.size.width, self.view.superview.frame.size.height);

        }      
    }];

}


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

    [UIView animateWithDuration:0.4 animations:^ {

        self.view.superview.frame = CGRectMake(self.view.superview.frame.origin.x, 212, self.view.superview.frame.size.width, self.view.superview.frame.size.height);
        }
    }];

}


推荐答案

而不是设置框架,使用CGAffineTransformTranslate,例如:

Instead of setting the frame, use CGAffineTransformTranslate, for example like so:

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    self.view.superview.transform = CGAffineTransformTranslate(self.view.superview.transform,0,72);
    }      
}];
}


-(void)textFieldDidEndEditing:(UITextField *)textField {
[UIView animateWithDuration:0.4 animations:^ {
    self.view.superview.transform = CGAffineTransformTranslate(self.view.superview.transform,0,-72);
    }
}];
}

这篇关于当键盘存在工作时,向上移动对话框,除非转动ipad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆