美文网首页iOS开发
键盘上移问题

键盘上移问题

作者: 飞鱼IOS | 来源:发表于2015-09-02 09:43 被阅读115次

    1、输入框监听UIControlEventEditingDidBegin事件,当用户开始输入时,将整个view上移。

    输入框监听UIControlEventEditingDidEnd事件,当用户结束输入时,将整个view下移,恢复到原位置。

    [textfield addTarget:self action:@selector(textFieldDidBeginEditing:) forControlEvents:UIControlEventEditingDidBegin];

    [textfield addTarget:self action:@selector(textFieldDidEndEditing:) forControlEvents:UIControlEventEditingDidEnd];

    通过tag值来确定每个textfield是否响应

    2//键盘监听

    [[NSNotificationCenter

    defaultCenter] addObserver:self

    selector:@selector(keyboardWillChangeFrame:)

    name:UIKeyboardWillChangeFrameNotification object:nil];

    - (void)keyboardWillChangeFrame:(NSNotification *)notification

    {

    CGRect isUpflag;

    [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&isUpflag];

    NSDictionary *info = [notification userInfo];

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

    [UIView animateWithDuration:0.25 animations:^{

    showView.center = CGPointMake(showView.center.x, self.view.center.y - kbSize.height);

    }];

    }

    kbSize.height可以获取键盘的高度

    原文地址 :http://blog.csdn.net/pzhtpf/article/details/9857857

    相关文章

      网友评论

        本文标题:键盘上移问题

        本文链接:https://www.haomeiwen.com/subject/bodlcttx.html