WEB开发网
开发学院手机开发iPhone 开发 textfiled自动适应软键盘高度 阅读

textfiled自动适应软键盘高度

 2012-09-07 12:18:27 来源:WEB开发网   
核心提示:- (id)init{ self = [super init]; if (self) { self.wantsFullScreenLayout = YES; [UIApplication sharedApplication].statusBarStyle = UIStatusBa
- (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];
}

Tags:textfiled 自动 适应

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接