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

                         }];

    }

  • 相关阅读:
    pythonchallenge 解谜 Level 6
    pythonchallenge 解谜 Level 5
    pythonchallenge 解谜 Level 4
    pythonchallenge 解谜 Level 3
    pythonchallenge 解谜 Level 2
    pythonchallenge 解谜 Level 1
    CCF 201912-2 回收站选址
    JavaWeb+JDBC+Servlet+SqlServer实现登录功能
    后台连接数据库的方法
    jQuery实现轮播图
  • 原文地址:https://www.cnblogs.com/StevenFu/p/3133635.html
Copyright © 2011-2022 走看看