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

- (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位置

}

文章来自:http://www.cnblogs.com/AlienY/p/4539931.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3