iOSで非常に単純な機能に悩まされています。iOSでキーボードを開いたときに送信ボタンが機能しない
スクロールビューのサブビュー内にあるtextFieldからデータを送信しようとしています。私が何かを書こうとするとすぐにキーボードが閉じられ、キーボードが開いたボタンが応答を停止すると、ボタンがヒットしたときにボタンがアクションを実行しています。
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]];
}
この上で何かを提案してください。 ありがとうございます。
私にあなたのコードを送ってもらえますか?私はあなたのコードの実際の問題は何かを示します。 –
私もコードを更新しました。 – Coder
をチェックしてください。あなたのコードはうまくいくかもしれませんが、キーボードショーで自動的にテキストフィールドのアニメーションを行うためにIQKeyboardManagerクラスを使用する必要があります。これはあなたの問題を解決するのに役立つかもしれません。 [リンク](https://github.com/hackiftekhar/IQKeyboardManager) –