在 iOS 中打开键盘时发送按钮不起作用
Send button is not working when keyboard opened in iOS
我被困在 iOS 中非常简单的功能中。
我正在尝试从滚动视图的子视图内的文本字段发送数据。当我按下按钮时按钮正在触发动作,当我尝试写东西时键盘关闭并且键盘打开按钮停止响应时。
VideoViewController:
-(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]];
}
请就此提出建议。
谢谢。
我也遇到过这个问题
我花了 2 天时间才找到解决方案。您需要将 ScrollVIew/View.
的取消触摸标志设置为 false
实际上,scrollview touch是启用的,它不允许按钮交互。
这是发送按钮不起作用的唯一原因。
我被困在 iOS 中非常简单的功能中。
我正在尝试从滚动视图的子视图内的文本字段发送数据。当我按下按钮时按钮正在触发动作,当我尝试写东西时键盘关闭并且键盘打开按钮停止响应时。
VideoViewController:
-(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]];
}
请就此提出建议。 谢谢。
我也遇到过这个问题
我花了 2 天时间才找到解决方案。您需要将 ScrollVIew/View.
的取消触摸标志设置为 false实际上,scrollview touch是启用的,它不允许按钮交互。
这是发送按钮不起作用的唯一原因。