【发布时间】:2017-06-23 11:11:02
【问题描述】:
我被困在 iOS 中非常简单的功能中。
我正在尝试从滚动视图的子视图内的 textField 发送数据。当我按下按钮时,按钮正在触发动作,当我尝试写东西时键盘关闭并且键盘打开按钮停止响应。
视频视图控制器:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
controller.videoID = videoID;
controller.channelID = channelID;
controller.view.frame = self.commentView.bounds;
[self.commentView addSubview:controller.view];
// [self.scrollView addSubview:controller.sendBtn];
[self addChildViewController:controller];
[controller didMoveToParentViewController:self];
}
评论视图控制器:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
controller.videoID = videoID;
controller.channelID = channelID;
controller.view.frame = self.commentView.bounds;
[self.commentView addSubview:controller.view];
// [self.scrollView addSubview:controller.sendBtn];
[self addChildViewController:controller];
[controller didMoveToParentViewController:self];
}
-(void)keyboardWillShow:(NSNotification *)notification
{
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = -keyboardSize.height+100;
self.sendView.frame = f;
}];
_sendBtn.userInteractionEnabled = YES;
}
-(void)keyboardWillHide:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = 0.0f;
self.sendView.frame = f;
}];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[commentTextField resignFirstResponder];
return YES;
}
- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
return ![view isKindOfClass:[UIButton class]];
}
请就此提出建议。 谢谢。
【问题讨论】:
-
你能把你的代码发给我吗?然后我会告诉你代码中的实际问题是什么。
-
我也更新了代码。请检查
-
您的代码会很好,但更好的建议是,您必须使用 IQKeyboardManager 类来自动为文本字段设置动画并显示键盘。这可能有助于解决您的问题。 link
-
在某些情况下检查此关键提示 stackoverflow.com/a/57698468/294884
标签: ios objective-c uiscrollview uibutton textfield