zoukankan      html  css  js  c++  java
  • uiviewcontroller 键盘不遮挡信息

    //添加监听事件
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
    //监听回调
    #pragma mark - keyboard 
    - (void)keyboardWillShow:(NSNotification*)notification {
    
        CGRect frame = self.view.frame;
        frame.origin.y -= 166;
        //frame.size.height +=216;
        // Shrink view's inset by the keyboard's height, and scroll to show the text field/view being edited
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
        [UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
        self.view.frame = frame;
        [UIView commitAnimations];
    }
    
    - (void)keyboardWillHide:(NSNotification*)notification {
    
        CGRect frame = self.view.frame;
        frame.origin.y += 166;
        //frame.size.height -=216;
        //self.view移回原位置
        // Restore dimensions to prior size
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
        [UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]];
        self.view.frame = frame;
        [UIView commitAnimations];
    }
  • 相关阅读:
    Merge Two Sorted Lists
    Palindrome Number
    Plus One
    Reverse Integer
    Read N Characters Given Read4
    Given two strings S and T, determine if they are both one edit distance apart
    Longest Palindromic Substring
    Missing Ranges
    Java 不被看好前景堪忧?可能是想多了!
    每天数十亿次请求的应用经验分享,值得参考!
  • 原文地址:https://www.cnblogs.com/Clin/p/3199349.html
Copyright © 2011-2022 走看看