From 8ae952ec8df2a713afeaef5960a88888e050c6fc Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 15 Oct 2017 23:47:11 +0300 Subject: WIP --- Juick/ViewControllers/NewPostViewController.m | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'Juick/ViewControllers/NewPostViewController.m') diff --git a/Juick/ViewControllers/NewPostViewController.m b/Juick/ViewControllers/NewPostViewController.m index 318de4e..9643b78 100644 --- a/Juick/ViewControllers/NewPostViewController.m +++ b/Juick/ViewControllers/NewPostViewController.m @@ -12,6 +12,7 @@ @interface NewPostViewController () @property (nonatomic, assign) BOOL didSetupConstraints; +@property (nonatomic, assign) int paddingValue; @end @@ -21,14 +22,17 @@ { [super viewDidLoad]; self.navigationController.visibleViewController.title = @"Post"; - self.view.backgroundColor = [ColorScheme mainBackground]; self.navigationController.visibleViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelCompose)]; self.navigationController.visibleViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd - target:self action:@selector(doneCompose)]; + target:self action:@selector(doneCompose)]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil]; + [self.textView becomeFirstResponder]; } - (void) cancelCompose { + [self.textView resignFirstResponder]; [self.navigationController.visibleViewController.navigationController popViewControllerAnimated:YES]; } @@ -36,4 +40,17 @@ [self.navigationController.visibleViewController.navigationController popToRootViewControllerAnimated:YES]; } +-(void) keyboardDidShow:(NSNotification *)sender { + CGRect frame = [sender.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; + CGRect newFrame = [self.view convertRect:frame fromView:[[UIApplication sharedApplication] delegate].window]; + [self.view layoutIfNeeded]; + [UIView animateWithDuration:[sender.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue] animations:^{ + self.bottomConstraint.constant = newFrame.origin.y - CGRectGetHeight(self.view.frame) + self.paddingValue; + [self.view layoutIfNeeded]; + }]; +} +-(void) keyboardWillHide:(NSNotification *)sender { + self.bottomConstraint.constant = self.paddingValue; + [self.view layoutIfNeeded]; +} @end -- cgit v1.2.3