ios textfiled自动适应软键盘高度

- (id)init
{
    self = [super init];
    if (self) {
        self.wantsFullScreenLayout = YES;
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackTranslucent;
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillHideNotification object:nil];
    }
    return self;
}


-(void)loadview
{
   titlefield.delegate = self;
}

#pragma mark -
#pragma mark - textfield delete

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    [self adjustPanelsWithKeybordHeight:0];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
	NSLog(@"should return");
	[self.sendpanel.titlefield resignFirstResponder];
	return YES;
}


- (void)keyboardWillChangeFrame:(NSNotification *)notification
{
    NSLog(@"keyboardWillChangeFrame");
    NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardBounds;
    [keyboardBoundsValue getValue:&keyboardBounds];
    NSLog(@"height = %f",keyboardBounds.size.height);
    [self adjustPanelsWithKeybordHeight:keyboardBounds.size.height];
}

-(void)adjustPanelsWithKeybordHeight:(float)height
{
    sendpanel.frame = CGRectMake(0, 435-height, sendpanel.frame.size.width, sendpanel.frame.size.height);
    progresspanel.frame = CGRectMake(0, 400-height, progresspanel.frame.size.width, progresspanel.frame.size.height);
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值