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) {

                         }];

    }

  • 相关阅读:
    解决Extjs分页工具条Ext.PagingToolbar无法换页问题 子曰
    使用“动软代码生成器”需要注意的问题 子曰
    格式化extjs DateField 的值 子曰
    构造extjs两级联动comBox 子曰
    SQLServer数据库设计表和字段(转) 子曰
    extjs 中取值的方式 子曰
    extjs中的控件无法正常显示 子曰
    extjs表单中的下拉框(comobobox)手动添加空选项 子曰
    C++基础学习笔记
    dhl:弹出div层,可关闭可移动
  • 原文地址:https://www.cnblogs.com/StevenFu/p/3133635.html
Copyright © 2011-2022 走看看