zoukankan      html  css  js  c++  java
  • [iOS]利用通知实现监听系统键盘

    //
    //  ViewController.m
    //  text
    //
    //  Created by 李东旭 on 16/1/22.
    //  Copyright © 2016年 李东旭. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    #import "ViewController.h"
    
    
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        UITextView *textV = [[UITextView alloc] initWithFrame:self.view.bounds];
        [self.view addSubview:textV];
        
        // 1. 添加通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardChange:) name:UIKeyboardWillShowNotification object:nil];
        // 键盘将要出现 UIKeyboardWillShowNotification
        // 键盘已经出现 UIKeyboardDidShowNotification
        // 键盘将要隐藏 UIKeyboardWillHideNotification
        // 键盘已经隐藏 UIKeyboardDidHideNotification
        
    }
    
    // 2. 键盘已经出现调用的触发方法
    - (void)keyBoardChange:(NSNotification *)noti
    {
        NSLog(@"%@", noti);
    // 打印noti
        /*
         0x7f84584d1000 {name = UIKeyboardDidShowNotification; userInfo = {
    // 键盘动画执行节奏
         UIKeyboardAnimationCurveUserInfoKey = 7;
         
    // 键盘动画的时间
         UIKeyboardAnimationDurationUserInfoKey = "0.25";
         
    // 键盘的bounds
         UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {375, 258}}";
         
    // 键盘的起始center
         UIKeyboardCenterBeginUserInfoKey = "NSPoint: {187.5, 796}";
         
    // 键盘的结束center
         UIKeyboardCenterEndUserInfoKey = "NSPoint: {187.5, 538}";
         
    // 键盘开始动画前的位置(也就是消失时)
         UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 667}, {375, 258}}";
         
    // 键盘结束动画后的位置(也就是弹出了)
         UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 409}, {375, 258}}";
    
         UIKeyboardIsLocalUserInfoKey = 1;
         }}
         */
        
        // 3. 那么如何获取这个值呢
        NSDictionary *noKey = [noti userInfo];
        NSValue *value = noKey[@"UIKeyboardBoundsUserInfoKey"];
        // 注意,这个的value 是CGRect类型的(所以下面必须调用CGRectValue方法
        NSLog(@"%f", [value CGRectValue].size.height);
        
    }
    
    
    @end
  • 相关阅读:
    OAuth2.0
    Base64编解码 代码
    Intent之Action
    android 之 WebView详解
    FCKeditor 在ASP.Net 中的使用说明
    css条件注释
    AspNetPager 服务器控件使用实例
    【转】分页控件ASPNETPAGET
    SQL server挂了之后
    应用主题后FCKeditor上传问题的解决及相应的改进
  • 原文地址:https://www.cnblogs.com/wangqi1221/p/5240217.html
Copyright © 2011-2022 走看看