zoukankan      html  css  js  c++  java
  • 键盘事件的处理

    1     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    2     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    View Code
     1 - (void)keyboardWillShow:(NSNotification *)notification {
     2     NSDictionary *userInfo = [notification userInfo];
     3     NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
     4     CGRect keyboardRect = [aValue CGRectValue];
     5     keyboardRect = [self.view convertRect:keyboardRect fromView:nil];
     6     
     7     CGFloat keyboardTop = keyboardRect.origin.y;
     8     CGRect newTextViewFrame = self.view.bounds;
     9     newTextViewFrame.size.height = keyboardTop - self.view.bounds.origin.y;
    10 
    11     NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    12     NSTimeInterval animationDuration;
    13     [animationDurationValue getValue:&animationDuration];
    14 
    15     [UIView beginAnimations:nil context:NULL];
    16     [UIView setAnimationDuration:animationDuration];
    17     
    18     self.myTableView.frame = newTextViewFrame;
    19     
    20     [UIView commitAnimations];
    21 }
    22 
    23 
    24 - (void)keyboardWillHide:(NSNotification *)notification {
    25     
    26     NSDictionary* userInfo = [notification userInfo];
    27     NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    28     NSTimeInterval animationDuration;
    29     [animationDurationValue getValue:&animationDuration];
    30     
    31     [UIView beginAnimations:nil context:NULL];
    32     [UIView setAnimationDuration:animationDuration];
    33     
    34     self.myTableView.frame = self.view.bounds;
    35     
    36     [UIView commitAnimations];
    37 }
  • 相关阅读:
    无监督聚类K-means算法
    Python程序执行顺序
    修改jupyter notebook响应的浏览器
    Vijos1035 贪婪的送礼者 [map的应用]
    POJ 2976 Dropping tests [二分]
    POJ 3111 K Best 最大化平均值 [二分]
    HDU 2899 Strange fuction [二分]
    HDU 2141 can you find it [二分]
    HDU 4004 The Frog's Games [二分]
    HDU 1969 Pie [二分]
  • 原文地址:https://www.cnblogs.com/yingkong1987/p/2808225.html
Copyright © 2011-2022 走看看