我的思路
創(chuàng)建一個(gè)自定義的評(píng)論框視圖砂蔽,添加到當(dāng)前view上赌朋,然后通過監(jiān)聽鍵盤的出現(xiàn)和消失控制評(píng)論框的位置。
IQKeyboardManager的做法
直接將評(píng)論框作為某個(gè)輸入框的inputAccessoryView屬性。
自己實(shí)現(xiàn)代碼代碼:
UITextField * contentField = [UITextField new];
[self.view addSubview:contentField];
contentField.backgroundColor = [UIColor yellowColor];
contentField.placeholder = @"輸入內(nèi)容...";
contentField.frame = CGRectMake(0, 280, 100, 30);
UIView * inputAccessoryView = [UIView new];
inputAccessoryView.frame = CGRectMake(0, 0, self.view.frame.size.width, 80);
inputAccessoryView.backgroundColor = [UIColor redColor];
[contentField setInputAccessoryView:inputAccessoryView];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
tap.numberOfTapsRequired = 1;
[inputAccessoryView addGestureRecognizer:tap];
效果圖:
inputaccessview.gif
本篇文章到這里就結(jié)束了榨为,愿大家加班不多工資多里初,男同胞都有女朋友啃勉,女同胞都有男朋友。??