zoukankan      html  css  js  c++  java
  • iOS开发中的键盘高度变化处理

    - (void)viewWillDisappear:(BOOL)animated

    {

    [[NSNotificationCenterdefaultCenter] removeObserver:selfname:UIKeyboardWillShowNotificationobject:nil];

    [[NSNotificationCenterdefaultCenter] removeObserver:selfname:UIKeyboardWillHideNotificationobject:nil];

    }

    - (void)viewDidLoad

    {

        [superviewDidLoad];

        

        [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotificationobject:nil];

        [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotificationobject:nil];

        

     }

    #pragma mark -

    #pragma mark Responding to keyboard events

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

        [self keyboardWillShowHide:notification];

    }

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

        [self keyboardWillShowHide:notification];

    }

    - (void)keyboardWillShowHide:(NSNotification *)notification

    {

        CGRect keyboardRect = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

    //UIViewAnimationCurve curve = [[notification.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];

    double duration = [[notification.userInfoobjectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];

        

        

        CGFloat keyboardY = [self.view convertRect:keyboardRect fromView:nil].origin.y;

        

        

        NSLog(@"keyboardY :%f",keyboardY);

        

        [UIViewanimateWithDuration:duration

                              delay:0.0f

                            options:UIViewAnimationOptionCurveEaseInOut//[UIView animationOptionsForCurve:curve]

                         animations:^{

                             CGFloat keyboardY = [self.view convertRect:keyboardRect fromView:nil].origin.y;

                             CGFloat keyboardH = [self.view convertRect:keyboardRect fromView:nil].size.height;

                             

                             imgUpload.frame = CGRectMake(5+33, keyboardY-33, 33, 33);

                             imgURL.frameCGRectMake(5, keyboardY-33, 33, 33);

                             

                             NSLog(@"keyboardY   %f",keyboardH);

                         }

                         completion:^(BOOL finished) {

                         }];

    }

  • 相关阅读:
    k8s资源编排
    虫师『软件测试』基础 与 测试杂谈
    虫师『性能测试』文章大汇总
    OMCS ——卓尔不群的网络语音视频聊天框架(跨平台)
    ESFramework ——成熟的C#网络通信框架(跨平台)
    2022.2 区块链的技术架构
    pytest文档80 内置 fixtures 之 cache 写入中文显示\u4e2d\u6587问题(用打补丁方式解决) 上海
    翻译校正
    Inside WCF Runtime
    Web Services Security
  • 原文地址:https://www.cnblogs.com/StevenFu/p/3133635.html
Copyright © 2011-2022 走看看