<UITextFieldDelegate>这个必须得写,,,啥也不说了。。。
/iphone5判断
#ifndef DEVICE_IS_IPHONE5
#define DEVICE_IS_IPHONE5 ([[UIScreen mainScreen] bounds].size.height == 568)
#endif
//iphone4判断
#ifndef DEVICE_IS_IPHONE4
#define DEVICE_IS_IPHONE4 ([[UIScreen mainScreen] bounds].size.height == 480)
#endif
这玩意得判断下 破手机 是什么 型号的,,6+以上就不用说了, 主要是为了 5—— 哎。。。惆怅ing、、、、
#pragma mark ---- UITextFieldDelegate
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if (DEVICE_IS_IPHONE4) {
CGRect rect = self.view.frame;
NSUInteger offsetY = 100;
if (textField == _userPswField) {
offsetY = 130;
}
rect.origin.y -= offsetY;
[UIView animateWithDuration:0.2 animations:^{
self.view.frame = rect;
} completion:nil];
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
if (DEVICE_IS_IPHONE4) {
CGRect rect = self.view.frame;
rect.origin.y = 0;
[UIView animateWithDuration:0.2 animations:^{
self.view.frame = rect;
} completion:nil];
}
}
//自己写的textField让这玩意遵循下 UITextFieldDelegate 代理方法 即可,,,
//触摸屏幕空白部分 回收键盘 即可,
//前提是背景为UIView 这个必须的!!!
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if ((![self.registV.phoneTextField isExclusiveTouch]) || (![self.registV.sendTextField isExclusiveTouch]) ||(![self.registV.passwordTextField isExclusiveTouch])) {
[self.registV.passwordTextField resignFirstResponder];
[self.registV.phoneTextField resignFirstResponder];
[self.registV.sendTextField resignFirstResponder];
}
}
//回收的代理方法。。。
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return NO;
}