【问题标题】:Send button is not working when keyboard opened in iOS在 iOS 中打开键盘时发送按钮不起作用
【发布时间】: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


【解决方案1】:

我也遇到过这个问题

我花了 2 天时间才找到解决方案。您需要将 ScrollVIew/View 的取消触摸标志设置为 false。

实际上,滚动视图触摸是启用的,它不允许按钮交互。

这是发送按钮不起作用的唯一原因。

【讨论】:

  • 好的。这可能是个问题。我一定会试试这个。谢谢
  • @user9363352 如何将取消触摸标志设置为 false?
猜你喜欢
  • 2017-10-01
  • 1970-01-01
  • 2018-06-20
  • 1970-01-01
  • 1970-01-01
  • 2015-09-17
  • 2019-11-19
  • 1970-01-01
  • 2015-09-13
相关资源
最近更新 更多