iOS 获取键盘相关信息

一,在需要的地方添加监听

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onKeyboardWillShowNotification:)
                                                 name:UIKeyboardWillShowNotification object:nil];
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onKeyboardWillHideNotification:)
                                                 name:UIKeyboardWillHideNotification object:nil];

二,响应监听方法

- (void)onKeyboardWillShowNotification:(NSNotification*)notify {
    NSDictionary *userInfoDic = [notify userInfo];
    NSLog(@"userInfoDic = %@", userInfoDic);
    CGFloat timerval = [[userInfoDic objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    NSValue *keyboardFrameValue = [userInfoDic objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardFrame = [keyboardFrameValue CGRectValue];
    [UIView animateWithDuration:timerval animations:^(void){
        self.containerView.frame = CGRectMake(self.containerView.frame.origin.x, self.containerView.frame.origin.y - keyboardFrame.size.height, self.containerView.frame.size.width, self.containerView.frame.size.height);
    }];
}
时间: 2024-08-26 14:22:45

iOS 获取键盘相关信息的相关文章

iOS获取手机相关信息

iOS具体的设备型号: #include <sys/types.h> #include <sys/sysctl.h> - (void)test { //手机型号. size_t size; sysctlbyname("hw.machine", NULL, &size, NULL, 0); char *machine = (char*)malloc(size); sysctlbyname("hw.machine", machine, &

iOS 获取APP相关信息 私有API

/* Generated by RuntimeBrowser Image: /System/Library/Frameworks/MobileCoreServices.framework/MobileCoreServices */ @interface LSApplicationWorkspace : NSObject // Image: /System/Library/Frameworks/MobileCoreServices.framework/MobileCoreServices + (i

获取IP相关信息和文件上传

获取IP相关信息 要获取用户访问者的IP地址相关信息,可以利用依赖注入,获取IHttpConnectionFeature的实例,从该实例上可以获取IP地址的相关信息,实例如下: var connection1 = Request.HttpContext.GetFeature<IHttpConnectionFeature>(); var connection2 = Context.GetFeature<IHttpConnectionFeature>(); var isLocal =

Linux sysinfo获取系统相关信息

Linux中,可以用sysinfo来获取系统相关信息. #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <linux/unistd.h> /* for _syscallX macros/related stuff */ #include <linux/kernel.h> /* for struct sysinfo */ //_syscall1(int, sysi

PHP获取手机相关信息

该PHP操作类实现获取手机号手机头信息,取UA,取得手机类型,判断是否是opera,判断是否是m3gate,取得HA,取得手机IP 代码如下: <?php /** * @desc 手机操作类 获取手机相关信息 * @since */class mobile { /** * 函数名称: getPhoneNumber * 函数功能: 取手机号 * 输入参数: none * 函数返回值: 成功返回号码,失败返回false * 其它说明: 说明 */ public function getPhoneNu

iOS获取键盘的高度(简洁有效)

iOS获取键盘的高度 (2013-03-06 17:45:31) 标签: keyboard textfield textview ios 键盘高度 分类: iOS笔记 - (void)viewDidLoad { [super viewDidLoad]; //增加监听,当键盘出现或改变时收出消息 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKe

iOS获取应用程序信息,版本号,程序名等

转载▼     iOS获取应用程序信息 NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; 其中的信息示范: 版本号:[infoDictionary objectForKey:@"CFBundleVersion"]; 应用程序名:[infoDictionary objectForKey:@"CFBundleDisplayName"]; { CFBundleDevelopment

借助Sigar API获取CPU相关信息

Sigar(全称System Information Gatherer And Reporter,即系统信息收集报表器),它提供了一个开源的跨平台的收集计算机硬件和操作系统信息的API(该API底层接口用C语言编写),本文将演示如何借助Sigar API获取CPU相关信息: package com.ghj.packageoftest; import org.hyperic.sigar.Cpu; import org.hyperic.sigar.CpuInfo; import org.hyperi

IOS 获取设备相关特性

一. 判断手机是否插入了SIM卡 解答: A.     私有 API 检测 [CTSIMSupportGetSIMStatus()isEqualToString:kCTSIMSupportSIMStatusNotInserted] 可以判断是否插入了 sim 卡. 前提是把下面的代码随便复制到一个头文件里面,然后引入CoreTelephony.framework 即可. 1    extern NSString* c*****tkCTSMSMessageReceivedNotification;