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