iOS——UIKeyboardWillShowNotification 监听键盘高度变化

时间:2015-05-30 10:39:54   收藏:0   阅读:3367

- (void)viewDidLoad {

    [super viewDidLoad];

    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 50)];

    textField.backgroundColor = [UIColor blueColor];

    [self.view addSubview:textField];

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

 

    };

 

-(void)keyboardWillShow:(NSNotification*)notification{

    NSDictionary*info=[notification userInfo];

    CGSize kbSize=[[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;

    NSLog(@"keyboard changed, keyboard width = %f, height = %f",

          kbSize.width,kbSize.height);

    //在这里调整UI位置

}

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!