Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)viewDidLoad {
- [super viewDidLoad];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(keyboardWillShow:)
- name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(keyboardWillHide:)
- name:UIKeyboardWillHideNotification object:nil];
- self.keyboardIsShown = NO;
- }
- -(void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:UIKeyboardWillShowNotification
- object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:UIKeyboardWillHideNotification
- object:nil];
- }
- -(void)keyboardWillShow:(NSNotification*)notification{
- if (self.keyboardIsShown) {
- return;
- }
- //change y Position of self.loginView
- self.keyboardIsShown = YES;
- }
- -(void)keyboardWillHide:(NSNotification*)notification{
- //Change y Position of self.loginView
- self.keyboardIsShown = NO;
- }
- UIKeyboardWillShowNotification
- UIKeyboardDidHideNotification
- - (void)viewWillAppear:(BOOL)animated {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
- }
- - (void)keyboardWillShow:(NSNotification *)notification
- {
- CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
- [UIView animateWithDuration:0.3 animations:^{
- CGRect f = self.view.frame;
- f.origin.y = -keyboardSize.height;
- self.view.frame = f;
- }];
- }
- -(void)keyboardWillHide:(NSNotification *)notification
- {
- [UIView animateWithDuration:0.3 animations:^{
- CGRect f = self.view.frame;
- f.origin.y = 0.0f;
- self.view.frame = f;
- }];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement