ios键盘遮挡问题

来源:互联网 发布:魔兽世界7.0多核优化 编辑:程序博客网 时间:2024/05/22 12:35

这个第三方可以看一下

IQKeyboardManager


-(void)viewWillAppear:(BOOL)animated

{

    [selfregisterForKeyboardNotifications];

}

-(void)viewWillDisappear:(BOOL)animated

{

    [[NSNotificationCenterdefaultCenter] removeObserver:self];

}

- (void)registerForKeyboardNotifications

{

    //使用NSNotificationCenter键盘出现

    [[NSNotificationCenterdefaultCenter] addObserver:self

     

                                             selector:@selector(keyboardWasShown:)

     

                                                 name:UIKeyboardDidShowNotificationobject:nil];

    

    //使用NSNotificationCenter键盘隐藏

    [[NSNotificationCenterdefaultCenter] addObserver:self

     

                                             selector:@selector(keyboardWillBeHidden:)

     

                                                 name:UIKeyboardWillHideNotificationobject:nil];

    

    

}

- (void)keyboardWasShown:(NSNotification*)aNotification

{

    if(![_tizitextisFirstResponder]){

    NSDictionary* info = [aNotification userInfo];

    //kbSize键盘尺寸 (width, height)

    CGSize kbSize = [[infoobjectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;//键盘的高度

    NSLog(@"hight_hitht:%f",kbSize.height);

        NSLog(@"%@",NSStringFromCGRect(_publish.frame));

#warning 后期根据尺寸修改

    [UIViewanimateWithDuration:0.1animations:^{

//最好用transform

        self.view.frame =CGRectMake(0, -60,self.view.frame.size.width,self.view.frame.size.height);

    }];}

    

}

//当键盘隐藏的时候

- (void)keyboardWillBeHidden:(NSNotification*)aNotification

{

    //do something

    [UIViewanimateWithDuration:0animations:^{

        self.view.frame =CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height);

    }];

}

0 0