Reputation: 579
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.
Upvotes: 0
Views: 1317
Reputation:
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.
Upvotes: 2