博客> 自定义键盘,遮挡textField
自定义键盘,遮挡textField
2017-10-16 13:00 评论:0 阅读:329 西单_夜未央

1.成为textField的代理,当然记得遵守协议

  • (void)viewDidLoad { [super viewDidLoad];

    self.textField1.delegate = self; self.textField2.delegate = self; self.textField3.delegate = self;

}

pragma textField 代理方法

  • (BOOL)textFieldShouldEndEditing:(UITextField *)textField {

    self.isBeingEditingTextField = textField;

    //这段代码啰嗦, 大家可以封装一下 if (textField.tag == 11) {

    self.label1.text = [NSString stringWithFormat:@" $ %@",textField.text];

    }

    if (textField.tag == 22) {

    self.label2.text = [NSString stringWithFormat:@" $ %@",textField.text];

    }

    if (textField.tag == 33) {

    self.label3.text = [NSString stringWithFormat:@" $ %@",textField.text];

    }

    self.bottomView.frame = CGRectMake(0, 100, self.view.bounds.size.width, self.view.bounds.size.height);

    self.bottomView.transform = CGAffineTransformIdentity;

    return YES; }

  • (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

    self.isBeingEditingTextField = textField;

//这里重点指出下面注释的方法是不行的.
// self.bottomView.frame = CGRectMake(0, 180, self.view.bounds.size.width, self.view.bounds.size.height);

//必须利用transform self.bottomView.transform = CGAffineTransformMakeTranslation(0, -50); return YES; }

//使键盘隐藏

  • (void)touchesBegan:(NSSet )touches withEvent:(UIEvent )event {

    [self.isBeingEditingTextField resignFirstResponder]; }

收藏
0
sina weixin mail 回到顶部