我的思路
创建一个自定义的评论框视图,添加到当前view上,然后通过监听键盘的出现和消失控制评论框的位置。
IQKeyboardManager的做法
直接将评论框作为某个输入框的inputAccessoryView属性。
自己实现代码代码:
UITextField * contentField = [UITextField new];
[self.view addSubview:contentField];
contentField.backgroundColor = [UIColor yellowColor];
contentField.placeholder = @"输入内容...";
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
本篇文章到这里就结束了,愿大家加班不多工资多,男同胞都有女朋友,女同胞都有男朋友。😊
网友评论