UIButton
每次我完成编辑时,我都会消失,UITextField
我调用该textFieldDidEndEditing:
方法,只是让按钮消失。这很好用,除非我切换到另一个文本字段而不单击第一个。因此,例如,我在文本字段 A 上,只需点击文本字段 B,键盘仍然保持不变,按钮也是如此。我不相信有一种方法可以覆盖这样的文本字段切换,只有在所有文本字段都完成编辑时。我错了吗?这是我的代码:
-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField
{
negButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
negButton.frame = CGRectMake(textField.frame.origin.x, textField.frame.origin.y, 37, textField.frame.size.height);
[negButton setAlpha:0];
return YES;
}
-(void) textFieldDidBeginEditing:(UITextField *)textField
{
if ([textField isEditing])
{
[UIView animateWithDuration:0.3 animations:^
{
field = textField;
CGRect frame = textField.frame;
frame.size.width -= 40;
frame.origin.x += 40;
[negButton setAlpha:1];
[textField setFrame:frame];
[self.view addSubview:negButton];
}];
}
}
-(void) textFieldDidEndEditing:(UITextField *)textField
{
[UIView animateWithDuration:0.3 animations:^
{
CGRect frame = textField.frame;
frame.size.width += 40;
frame.origin.x -= 40;
[negButton setAlpha:0];
[textField setFrame:frame];
}
];
}