0

I am stuck in very simple functionality in iOS.

I am trying to send the data from a textField which is inside the subview of a scroll view. Button is firing the action when I hit the button, when keyboard is closed as soon as I try to write something and keyboard opened button stop responding.

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];
}

CommentViewController:

-(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]];
}

Please suggest something on this. Thank you.

Sid Mhatre
  • 3,272
  • 1
  • 19
  • 38
UGandhi
  • 518
  • 1
  • 8
  • 28
  • 1
    can you send me or show me your code? then i will show that whats the actual problem in your code. – amit_donga Feb 06 '17 at 13:31
  • I have updated the code as well. Please check – UGandhi Feb 06 '17 at 13:44
  • 1
    your code will fine but better suggestion to you have to use IQKeyboardManager class for textfield animate automatically with keyboard show. this may be help to solve your problem. [link](https://github.com/hackiftekhar/IQKeyboardManager) – amit_donga Feb 06 '17 at 14:03
  • in some case check this **CRITICAL TIP** https://stackoverflow.com/a/57698468/294884 – Fattie Jun 28 '20 at 10:22

1 Answers1

2

I faced this problem, too

It took me 2 days to find the solution. You need to set the cancel touches flag to false for ScrollVIew/View.

Actually, scrollview touch is enable and it is not allowing the button to interact.

This is the only reason send button is not working.