Skip to content

Commit

Permalink
#9 Almost
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Oct 5, 2013
1 parent f1f47a9 commit 6642186
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Chromatism/Chromatism/JLTextViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,33 @@ - (void)keyboardWasShown:(NSNotification *)notification
UIScrollView *scrollView = self.textView;
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
UIEdgeInsets contentInsets = scrollView.contentInset;
contentInsets.bottom = kbSize.height;
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;

//CGPoint caretPosition = [self.textView caretRectForPosition:self.textView.selectedTextRange.start].origin;
//CGRect caretRect = CGRectMake(caretPosition.x, caretPosition.y, 1, 1);
//[self.textView scrollRectToVisible:caretRect animated:YES];
CGPoint point = [self.textView caretRectForPosition:self.textView.selectedTextRange.start].origin;
point.y = MIN(point.y, self.textView.frame.size.height - kbSize.height);

CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, point) ) {

CGRect rect = CGRectMake(point.x, point.y, 1, 1);
rect.size.height = kbSize.height;
rect.origin.y += kbSize.height;
[self.textView scrollRectToVisible:rect animated:YES];
}
}

// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification *)notification
{
UIScrollView *scrollView = self.textView;
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
UIEdgeInsets contentInsets = scrollView.contentInset;
contentInsets.bottom = 0;
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;
}
Expand Down
1 change: 1 addition & 0 deletions ChromatismDemo/ChromatismDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
NSString *string = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:URL] encoding:NSUTF8StringEncoding];

JLTextViewController *viewController = [[JLTextViewController alloc] initWithText:string];
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Resign" style:UIBarButtonItemStylePlain target:viewController.textView action:@selector(resignFirstResponder)];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
viewController.title = @"Chromatism";

Expand Down

0 comments on commit 6642186

Please sign in to comment.