Skip to content

Commit

Permalink
Fixed issue with keyboard covering toolbar on iPhone
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhubbard committed Jun 23, 2015
1 parent 17053be commit 6952c0c
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions ZSSRichTextEditor/Source/ZSSRichTextEditor.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,8 @@ - (void)viewDidLoad {
line.backgroundColor = [UIColor lightGrayColor];
line.alpha = 0.7f;
[toolbarCropper addSubview:line];

// j5136p1 12/08/2014 : On iphone we add toolbar to view
[self.view addSubview:self.toolbarHolder];
}else
// j5136p1 12/08/2014 : On iPad we add toolbar to keyWindow
[[UIApplication sharedApplication].keyWindow addSubview:self.toolbarHolder];
}
[self.view addSubview:self.toolbarHolder];

// Build the toolbar
[self buildToolbar];
Expand Down Expand Up @@ -532,15 +528,14 @@ - (void)viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowOrHide:) name:UIKeyboardWillHideNotification object:nil];
}

// j5136p1 12/08/2014 : remove observer diddisappear. willdisappear is to early
-(void)viewDidDisappear:(BOOL)animated{

[super viewDidDisappear:animated];
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];

}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
Expand Down Expand Up @@ -1230,15 +1225,12 @@ - (void)keyboardWillShowOrHide:(NSNotification *)notification {

// Toolbar
CGRect frame = self.toolbarHolder.frame;
// j5136p1 12/08/2014 : Set y position in keywindow not in view. To handle also ex. modal views
frame.origin.y = [UIApplication sharedApplication].keyWindow.frame.size.height - (keyboardHeight + sizeOfToolbar);
frame.origin.y = self.view.frame.size.height - (keyboardHeight + sizeOfToolbar);
self.toolbarHolder.frame = frame;

// Editor View

const int extraHeight = 10;


CGRect editorFrame = self.editorView.frame;
editorFrame.size.height = (self.view.frame.size.height - keyboardHeight) - sizeOfToolbar - extraHeight;
self.editorView.frame = editorFrame;
Expand All @@ -1255,16 +1247,14 @@ - (void)keyboardWillShowOrHide:(NSNotification *)notification {
[self setFooterHeight:(keyboardHeight - 8)];
[self setContentHeight: self.editorViewFrame.size.height];


} completion:nil];

} else {

[UIView animateWithDuration:duration delay:0 options:animationOptions animations:^{

CGRect frame = self.toolbarHolder.frame;
// j5136p1 12/08/2014 : Set y position in keywindow not in view. To handle also ex. modal views
frame.origin.y = [UIApplication sharedApplication].keyWindow.frame.size.height + keyboardHeight;
frame.origin.y = self.view.frame.size.height + keyboardHeight;
self.toolbarHolder.frame = frame;

// Editor View
Expand Down Expand Up @@ -1351,4 +1341,4 @@ - (void)enableToolbarItems:(BOOL)enable {
}


@end
@end

0 comments on commit 6952c0c

Please sign in to comment.