我的app弹出键盘时 如果是第三方键盘会挡住底下的一个VIEW,我看过第三方键盘的userinfo 里面显示高度为0 这种情况下我怎样才能让我底下的VIEW紧贴着键盘的顶端显示??我试过的第三方键盘是搜狗和百度我想达到的效果是想微信一样 就算切换键盘但是输入框还是紧贴在键盘上面谢谢各位大神!!

解决方案 »

  1.   

    给你推荐一个第三方框架:https://github.com/hackiftekhar/IQKeyboardManager
    使用方法也很简单,属于单例模式,在程序启动时调用一次就可以。
    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;
    }希望能够帮到你。
      

  2.   

    在 清单文件中  申明 Activity时
    添加 
     android:windowSoftInputMode="adjustResize"
      

  3.   


    我的问题是在IOS上的, 你这个用得了么??
      

  4.   

    监听键盘通知不行么?
    在keyboardWillChangeFrame:里面改变View的frame
      

  5.   


    可以的。
    /**
     *  保存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))];
        }
    }