Skip to content

Instantly share code, notes, and snippets.

@JeffNixonCreative
Created June 11, 2014 04:10
Show Gist options
  • Select an option

  • Save JeffNixonCreative/208b3e03eae6dc97f924 to your computer and use it in GitHub Desktop.

Select an option

Save JeffNixonCreative/208b3e03eae6dc97f924 to your computer and use it in GitHub Desktop.
//
// WeekOneViewController.m
// weekone
//
// Created by Jeffrey Nixon on 6/6/14.
// Copyright (c) 2014 Jeff Nixon Creative. All rights reserved.
//
#import "WeekOneViewController.h"
@interface WeekOneViewController ()
@property (strong, nonatomic) IBOutlet UIView *mainContainer;
@property (strong, nonatomic) IBOutlet UIView *postField;
@property (strong, nonatomic) IBOutlet UIView *textField;
- (void)willShowKeyboard:(NSNotification *)notification;
- (void)willHideKeyboard:(NSNotification *)notification;
- (IBAction)onTap:(id)sender;
@end
@implementation WeekOneViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Register the method for the keyboard hide/show events
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willShowKeyboard:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willHideKeyboard:) name:UIKeyboardWillHideNotification object:nil];
}
return self;
}
- (void)willShowKeyboard:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
NSLog(@"Height: %f Width: %f", kbSize.height, kbSize.width);
NSNumber *durationValue = userInfo[UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval animationDuration = durationValue.doubleValue;
NSNumber *curveValue = userInfo[UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve animationCurve = curveValue.intValue;
// I gotta move it move it, we gotta move it move it, YOU....gotta MOVE IT
[UIView animateWithDuration:animationDuration
delay:0.0
options:(animationCurve << 16)
animations:^{
self.textField.frame = CGRectMake(0, self.view.frame.size.height - kbSize.height - self.textField.frame.size.height, self.textField.frame.size.width, self.textField.frame.size.height);
}
completion:nil];
}
- (void)willHideKeyboard:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
// Ohhhhhhhyeah baby I'm half way there with a little time to spair ;)
NSNumber *durationValue = userInfo[UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval animationDuration = durationValue.doubleValue;
NSNumber *curveValue = userInfo[UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve animationCurve = curveValue.intValue;
// Oh snap I'm in the red with no time to spair :(
[UIView animateWithDuration:animationDuration
delay:0.0
options:(animationCurve << 16)
animations:^{
self.textField.frame = CGRectMake(0, self.view.frame.size.height - self.textField.frame.size.height, self.textField.frame.size.width, self.textField.frame.size.height);
}
completion:nil];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.mainContainer.layer.cornerRadius = 3;
self.mainContainer.layer.shadowColor = [UIColor blackColor].CGColor;
self.mainContainer.layer.shadowOffset = CGSizeMake(0,1);
self.mainContainer.layer.shadowOpacity = .15;
self.mainContainer.layer.shadowRadius = 3;
self.postField.layer.shadowColor = [UIColor blackColor].CGColor;
self.postField.layer.shadowOffset = CGSizeMake(0,-1);
self.postField.layer.shadowOpacity = .05;
self.postField.layer.shadowRadius = 2;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)onTap:(id)sender {
[self.view endEditing: YES];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment