第三方键盘问题 我的app弹出键盘时 如果是第三方键盘会挡住底下的一个VIEW,我看过第三方键盘的userinfo 里面显示高度为0 这种情况下我怎样才能让我底下的VIEW紧贴着键盘的顶端显示??我试过的第三方键盘是搜狗和百度我想达到的效果是想微信一样 就算切换键盘但是输入框还是紧贴在键盘上面谢谢各位大神!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你推荐一个第三方框架:https://github.com/hackiftekhar/IQKeyboardManager使用方法也很简单,属于单例模式,在程序启动时调用一次就可以。pod 导入方法:platform :ios, '8.0'#use_frameworks!个别需要用到它,比如reactiveCocoadef podspod 'IQKeyboardManager'endtarget 'name' do podsend使用方法:在AppDelegate中导入头文件,#import "IQKeyboardManager.h"然后在程序生命周期方法didFinishLaunchingWithOptions中调一次即可:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self KeyBoard]; return YES;}-(void)KeyBoard{ IQKeyboardManager *manager = [IQKeyboardManager sharedManager]; // 控制整个功能是否启用。 manager.enable = YES; // 控制点击背景是否收起键盘 manager.shouldResignOnTouchOutside = YES; // 控制键盘上的工具条文字颜色是否用户自定义 manager.shouldToolbarUsesTextFieldTintColor = YES; // 控制是否显示键盘上的工具条 manager.enableAutoToolbar = YES; // 控制是否显示工具条上的文字 manager.shouldShowTextFieldPlaceholder = NO; // 最新版的设置键盘的returnKey的关键字 ,可以点击键盘上的next键,自动跳转到下一个输入框,最后一个输入框点击完成,自动收起键盘。 manager.toolbarManageBehaviour = IQAutoToolbarByTag;}希望能够帮到你。 在 清单文件中 申明 Activity时添加 android:windowSoftInputMode="adjustResize" 我的问题是在IOS上的, 你这个用得了么?? 监听键盘通知不行么?在keyboardWillChangeFrame:里面改变View的frame 可以的。/** * 保存UITextfile y轴坐标到view底部的距离,默认为0 */@property (assign, nonatomic) float Keyhei;- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self Keybord];}#pragma - 键盘处理-(void)Keybord{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; //隐藏键盘 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; }- (void)keyboardWillHide:(NSNotification *)notif{ NSDictionary *info = [notif userInfo]; CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; [self.ScollerView setContentOffset:CGPointMake(0, 0)]; CGRect frame = self.view.frame; int offset = frame.origin.y + 32 - (self.view.frame.size.height - keyboardSize.height); NSTimeInterval animationDuration = 0.30f; [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; [UIView setAnimationDuration:animationDuration]; //将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示 if(offset < 0) self.ScollerView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); [UIView commitAnimations];}//显示键盘-(void)keyboardWillShow:(NSNotification *)note{ NSDictionary *info = [note userInfo]; CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; CGRect frame = self.view.frame; int offset = frame.origin.y + 32 - (self.view.frame.size.height - keyboardSize.height); NSTimeInterval animationDuration = 0.30f; [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; [UIView setAnimationDuration:animationDuration]; //将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示 if(offset < 0) { } [UIView commitAnimations]; if(self.Keyhei >= keyboardSize.height) { return; }else{ [self.ScollerView setContentOffset:CGPointMake(0, 100 + (keyboardSize.height - self.Keyhei))]; }} ios 腾讯微博授权界面问题 新手iphone菜鸟问题...在线等回复 IOS7开发中如何在一个类刷新另一个UIViewController IOS多人协作开发的解决方案? ios能否获得用户屏幕开启的时间?和耳机使用的时间以及通话时间? iOS开发:一个奇怪的问题 IOS有锁定屏幕的代码吗? xib自定义的view 重新创建不显示 ios10相册访问权限问题 用webview加载pdf iOS 10.1.1不支持pdf1.2版本 xcode 里设置一个文件夹里的图片为背景图失败。 uicollectionviewcell 里的子控件创建不成功
使用方法也很简单,属于单例模式,在程序启动时调用一次就可以。
pod 导入方法:platform :ios, '8.0'
#use_frameworks!个别需要用到它,比如reactiveCocoadef pods
pod 'IQKeyboardManager'
end
target 'name' do
pods
end
使用方法:
在AppDelegate中导入头文件,#import "IQKeyboardManager.h"然后在程序生命周期方法didFinishLaunchingWithOptions中调一次即可:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self KeyBoard]; return YES;
}-(void)KeyBoard
{
IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
// 控制整个功能是否启用。
manager.enable = YES;
// 控制点击背景是否收起键盘
manager.shouldResignOnTouchOutside = YES;
// 控制键盘上的工具条文字颜色是否用户自定义
manager.shouldToolbarUsesTextFieldTintColor = YES;
// 控制是否显示键盘上的工具条
manager.enableAutoToolbar = YES;
// 控制是否显示工具条上的文字
manager.shouldShowTextFieldPlaceholder = NO;
// 最新版的设置键盘的returnKey的关键字 ,可以点击键盘上的next键,自动跳转到下一个输入框,最后一个输入框点击完成,自动收起键盘。
manager.toolbarManageBehaviour = IQAutoToolbarByTag;
}希望能够帮到你。
添加
android:windowSoftInputMode="adjustResize"
我的问题是在IOS上的, 你这个用得了么??
在keyboardWillChangeFrame:里面改变View的frame
可以的。
/**
* 保存UITextfile y轴坐标到view底部的距离,默认为0
*/
@property (assign, nonatomic) float Keyhei;- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self Keybord];
}
#pragma - 键盘处理
-(void)Keybord
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
//隐藏键盘
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}- (void)keyboardWillHide:(NSNotification *)notif
{
NSDictionary *info = [notif userInfo];
CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
[self.ScollerView setContentOffset:CGPointMake(0, 0)];
CGRect frame = self.view.frame;
int offset = frame.origin.y + 32 - (self.view.frame.size.height - keyboardSize.height);
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
//将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示
if(offset < 0)
self.ScollerView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}
//显示键盘
-(void)keyboardWillShow:(NSNotification *)note
{
NSDictionary *info = [note userInfo];
CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; CGRect frame = self.view.frame;
int offset = frame.origin.y + 32 - (self.view.frame.size.height - keyboardSize.height);
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
//将视图的Y坐标向上移动offset个单位,以使下面腾出地方用于软键盘的显示
if(offset < 0)
{
}
[UIView commitAnimations];
if(self.Keyhei >= keyboardSize.height)
{
return;
}else{
[self.ScollerView setContentOffset:CGPointMake(0, 100 + (keyboardSize.height - self.Keyhei))];
}
}