From a84bd41d58e5f5d5379fdcf6f32cf93ea0d6b4ec Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sun, 3 May 2015 16:12:14 -0700 Subject: [PATCH] add a cheesy button to hide the keyboard --- Blog/EditorViewController.m | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Blog/EditorViewController.m b/Blog/EditorViewController.m index 52e1957..c822e70 100644 --- a/Blog/EditorViewController.m +++ b/Blog/EditorViewController.m @@ -166,6 +166,8 @@ [super viewWillAppear:animated]; NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; [notificationCenter addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil]; + [notificationCenter addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; + [notificationCenter addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; if ([self pasteboardHasLink]) { [self configureLinkView]; } @@ -175,6 +177,8 @@ [super viewWillDisappear:animated]; NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; [notificationCenter removeObserver:self name:UIApplicationWillResignActiveNotification object:nil]; + [notificationCenter removeObserver:self name:UIKeyboardWillShowNotification object:nil]; + [notificationCenter removeObserver:self name:UIKeyboardWillHideNotification object:nil]; [self savePost]; } @@ -193,8 +197,28 @@ - (void)applicationWillResignActive:(NSNotification *)note { [self savePost]; } + +- (void)keyboardWillShow:(NSNotification *)note { + [self showHideKeyboardButton]; +} + +- (void)keyboardWillHide:(NSNotification *)note { + [self hideHideKeyboardButton]; +} + #pragma mark - +- (void)showHideKeyboardButton; +{ + UIBarButtonItem *hideKeyboardItem = [[UIBarButtonItem alloc] initWithTitle:@"^^" style:UIBarButtonItemStylePlain target:self.textView action:@selector(resignFirstResponder)]; + self.navigationItem.rightBarButtonItem = hideKeyboardItem; +} + +- (void)hideHideKeyboardButton; +{ + self.navigationItem.rightBarButtonItem = nil; +} + - (BOOL)isDirty; { return self.modifiedPost.new || ![self.modifiedPost isEqualToPost:self.post];