IOS——UITextField自动适应键盘弹出

来源:互联网 发布:wps mac 编辑:程序博客网 时间:2024/05/20 16:41
    //键盘变化监听    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardChange:) name:@"UIKeyboardWillChangeFrameNotification" object:nil];



- (void)keyboardChange:(NSNotification *)aNotification{    NSValue *value = [[aNotification userInfo] objectForKey:@"UIKeyboardFrameEndUserInfoKey"];    float keyEnd_y = [value CGRectValue].origin.y;    float animationDuration = [[aNotification userInfo][@"UIKeyboardAnimationDurationUserInfoKey"] floatValue];            CGRect frame = [[UIScreen mainScreen]bounds];//屏幕尺寸    CGRect viewFrame = self.view.frame;    viewFrame.origin.y = keyEnd_y - frame.size.height;    self.view.frame = viewFrame;        [UIView animateWithDuration:animationDuration animations:^{    }];    }


0 0