我发这篇的初衷很简单, 就是我用到得时候直接copy的, 完全没有技术难点什么的
#pragma mark ----编辑不被遮挡
// textField上移动画
- (void)textFieldAnimate:(UITextField*)textField isUp:(BOOL)isUp{
int movementDistance =140;
// 根据需要调整平移距离
float movementDuration = 0.3f;
int movement = (isUp ? -movementDistance : movementDistance);
[UIViewbeginAnimations:@"textFieldAnimation" context:nil];
[UIViewsetAnimationBeginsFromCurrentState:YES];
[UIViewsetAnimationDuration:movementDuration];
self.view.frame= CGRectOffset(self.view.frame,0, movement);
[UIViewcommitAnimations];
}
#pragma mark- TextField Delegate
- (void)textFieldDidBeginEditing:(UITextField*)textField{
[selftextFieldAnimate:textFieldisUp:YES];
}
- (void)textFieldDidEndEditing:(UITextField*)textField{
[selftextFieldAnimate:textFieldisUp:NO];
}
#pragma mark ----键盘消失
- (void)resignKeyboard
{
[_communityTFresignFirstResponder];
}
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
[_communityTFresignFirstResponder];
// textField上移动画
- (void)textFieldAnimate:(UITextField*)textField isUp:(BOOL)isUp{
int movementDistance =140;
// 根据需要调整平移距离
float movementDuration = 0.3f;
int movement = (isUp ? -movementDistance : movementDistance);
[UIViewbeginAnimations:@"textFieldAnimation" context:nil];
[UIViewsetAnimationBeginsFromCurrentState:YES];
[UIViewsetAnimationDuration:movementDuration];
self.view.frame= CGRectOffset(self.view.frame,0, movement);
[UIViewcommitAnimations];
}
#pragma mark- TextField Delegate
- (void)textFieldDidBeginEditing:(UITextField*)textField{
[selftextFieldAnimate:textFieldisUp:YES];
}
- (void)textFieldDidEndEditing:(UITextField*)textField{
[selftextFieldAnimate:textFieldisUp:NO];
}
#pragma mark ----键盘消失
- (void)resignKeyboard
{
[_communityTFresignFirstResponder];
}
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
[_communityTFresignFirstResponder];
}
#pragma mark ----修改placeholder的字体颜色、大小
- textField.placeholder = @"username is in here!";
- [textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
- [textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];