-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainViewController.m
More file actions
104 lines (81 loc) · 4.08 KB
/
Copy pathMainViewController.m
File metadata and controls
104 lines (81 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// MainViewController.m
// Week1
//
// Created by Tom Gurka on 6/6/14.
// Copyright (c) 2014 tom. All rights reserved.
//
#import "MainViewController.h"
@interface MainViewController ()
@property (weak, nonatomic) IBOutlet UIView *introView;
@property (weak, nonatomic) IBOutlet UIView *commentImageView;
- (void)willShowKeyboard:(NSNotification *)notification;
- (void)willHideKeyboard:(NSNotification *)notification;
@end
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
// Register the methods 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)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//introView Customizations
self.introView.layer.cornerRadius = 2;
//un-needed customizations, but required anyways
//self.introView.layer.backgroundColor = (__bridge CGColorRef)([UIColor whiteColor]);
//self.introView.layer.shadowColor = [UIColor yellowColor].CGColor;
//self.introView.layer.shadowOffset = CGSizeMake(10,10);
//self.introView.layer.shadowOpacity = 1;
//self.introView.layer.shadowRadius = 10;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)willShowKeyboard:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
// Get the keyboard height and width from the notification
// Size varies depending on OS, language, orientation
CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
NSLog(@"Height: %f Width: %f", kbSize.height, kbSize.width);
// Get the animation duration and curve from the notification
NSNumber *durationValue = userInfo[UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval animationDuration = durationValue.doubleValue;
NSNumber *curveValue = userInfo[UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve animationCurve = curveValue.intValue;
// Move the view with the same duration and animation curve so that it will match with the keyboard animation
[UIView animateWithDuration:animationDuration
delay:0.0
options:(animationCurve << 16)
animations:^{
self.commentImageView.frame = CGRectMake(0, self.view.frame.size.height - kbSize.height - self.commentImageView.frame.size.height, self.commentImageView.frame.size.width, self.commentImageView.frame.size.height);
}
completion:nil];
}
- (void)willHideKeyboard:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
// Get the animation duration and curve from the notification
NSNumber *durationValue = userInfo[UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval animationDuration = durationValue.doubleValue;
NSNumber *curveValue = userInfo[UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve animationCurve = curveValue.intValue;
// Move the view with the same duration and animation curve so that it will match with the keyboard animation
[UIView animateWithDuration:animationDuration
delay:0.0
options:(animationCurve << 16)
animations:^{
self.commentImageView.frame = CGRectMake(0, self.view.frame.size.height - self.commentImageView.frame.size.height, self.commentImageView.frame.size.width, self.commentImageView.frame.size.height);
}
completion:nil];
}
@end