键盘弹出高度和遮挡问题

#import "LoginViewController.h"

#import "ClssNameViewController.h"

@interface LoginViewController ()<UITextFieldDelegate>

@property (strong, nonatomic) IBOutlet UIButton *buttonLogin;

@property (strong, nonatomic) IBOutlet UITextField *textName;

@property (strong, nonatomic) IBOutlet UITextField *textPwd;

@property (strong, nonatomic) IBOutlet UITextField *textSelect;


@end


@implementation LoginViewController

-(void)viewDidAppear:(BOOL)animated

{

    [super viewDidAppear:animated];

    [[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(keyboardDidShowOrHide:)

                                                 name:UIKeyboardWillShowNotification

                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(keyboardDidShowOrHide:)

                                                 name:UIKeyboardWillHideNotification

                                               object:nil];

}

-(void)viewWillDisappear:(BOOL)animated

{

    [super viewWillDisappear:animated];

     [[NSNotificationCenter defaultCenter] removeObserver:self];

    

}

#pragma mark - Keyboard methods

/*

 view将要上升的高度 键盘高度-(屏幕高度 文本框在view上的y坐标);

 */

-(void)keyboardDidShowOrHide:(NSNotification *)notification

{

    NSDictionary *userInfo = [notification userInfo];

    NSTimeInterval animationDuration;

    UIViewAnimationCurve animationCurve;

    CGRect keyboardEndFrame;//键盘的frame

    

    [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];

    [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];

    [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];

    

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:animationDuration];

    [UIView setAnimationCurve:animationCurve];

    

    CGRect newFrame = self.view.frame;//viewframe

   

    

    if (self.textSelect == nil) {

        newFrame.origin.y = 0.0;

    }

    else

    {

        newFrame.origin.y = keyboardEndFrame.origin.y - newFrame.size.height;

    }

    self.view.frame = newFrame;

    

    [UIView commitAnimations];

}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

{

    self.textSelect = textField;

    return YES;

}

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.textPwd.delegate = self;

    self.textName.delegate = self;

    UIImageView* imageViewTap = (UIImageView* )[self.view viewWithTag:1];

    imageViewTap.userInteractionEnabled = YES;

    UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapConcelText:)];

    [imageViewTap addGestureRecognizer:tap];

}

-(void)tapConcelText:(UITapGestureRecognizer*)tap

{

    self.textSelect = nil;

    [self.textPwd resignFirstResponder];

    [self.textName resignFirstResponder];

 

}


@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值