#pragma mark - 屏幕上弹
-( void )textFieldDidBeginEditing:(UITextField *)textField
{
//键盘高度216
//滑动效果(动画)
NSTimeInterval animationDuration = 0.50f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
//将视图的Y坐标向上移动,以使下面腾出地方用于软键盘的显示
self.view.frame = CGRectMake(0.0f, -kHeightScale*150, self.view.frame.size.width, self.view.frame.size.height); //64-216
[UIView commitAnimations];
}
#pragma mark -屏幕恢复
-( void )textFieldDidEndEditing:(UITextField *)textField
{
//滑动效果
NSTimeInterval animationDuration = 0.50f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
//恢复屏幕
self.view.frame = CGRectMake(0.0f, 64.0f, self.view.frame.size.width, self.view.frame.size.height); //64-216
[UIView commitAnimations];
}
//限制输入字符
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSMutableString * futureString = [NSMutableString stringWithString:textField.text];
[futureString insertString:string atIndex:range.location];
NSInteger flag=0;
const NSInteger limited = 0;
for (int i = futureString.length-1; i>=0; i--) {
if ([futureString characterAtIndex:i] == '.') {
if (flag > limited) {
return NO;
}
break;
}
flag++;
}
return YES;
}