zoukankan      html  css  js  c++  java
  • 监听键盘的出现和隐藏顶部View值得改变

    - (UITextView *)publishTextView

    {

        if (!_publishTextView)

        {

            UITextView *publishTextView = [[UITextView alloc] init];

            

            publishTextView.font = ContentTitleFont;

            publishTextView.frame = CGRectMake(0, 0, Screen_Width, Screen_Height);

            // 键盘成为第一响应者

            [publishTextView becomeFirstResponder];

            

            self.publishTextView = publishTextView;

            [self.view addSubview:publishTextView];

        }

        return _publishTextView;

    }

    - (YSWeiBoPublishToolbar *)publishToolbar

    {

        if (!_publishToolbar)

        {

            YSWeiBoPublishToolbar *publishToolbar = [[YSWeiBoPublishToolbar alloc] init];

            

            CGFloat publishToolbarHeight = 44.f;

            publishToolbar.frame = CGRectMake(0, Screen_Height - publishToolbarHeight, Screen_Width, publishToolbarHeight);

            

            self.publishToolbar = publishToolbar;

            [self.view addSubview:publishToolbar];

        }

        return _publishToolbar;

    }

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        

        self.publishTextView.delegate = self;

        self.publishToolbar;

        [self setupNavigationItem];

        [YSWeiBoNotificationCenter addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];

    }

    #pragma mark - 监听方法

    /** */

    - (void)keyboardWillChangeFrame:(NSNotification *)notification

    {

        NSDictionary *userInfo = notification.userInfo;

        // 动画的持续时间

        double duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];

        // 键盘的frame

        CGRect keyboardF = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

        

        [UIView animateWithDuration:duration animations:^{

            if (keyboardF.origin.y > self.view.height) { // 键盘的Y值已经远远超过了控制器view的高度

                self.publishToolbar.y = self.view.height - self.publishToolbar.height;

            } else {

                self.publishToolbar.y = keyboardF.origin.y - self.publishToolbar.height;

            }

        }];

    }

  • 相关阅读:
    POI Excel解析
    mysql忘记root密码的解决方法
    注解实现AOP
    Java 集合类
    easyui-textbox 绑定事件
    MarqueeLabel 跑马灯
    Swift-2.14构造过程
    Swift-2.13继承
    Swift- 2.12下标脚本
    Swift-2.11方法
  • 原文地址:https://www.cnblogs.com/happyEveryData/p/5515289.html
Copyright © 2011-2022 走看看