three20 解决tttaleviewcontroller 切换输入法的bug

 

  three20 比较方便,只要将autoresizesForKeyboard = YES就可以自动调整键盘位置,但是有一个bug,如果切换输入法将会导致view 消失,后来查了一下,找到了如下解决方法,可以直接将TTTableViewController.m 中代码替换成如下:当然我建议还是继承一下TTTableViewController,然后在子类中处理。

 

 

///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark TTViewController


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)keyboardDidAppear:(BOOL)animated withBounds:(CGRect)bounds {
    [super keyboardDidAppear:animated withBounds:bounds];
    CGRect screenRectInTableSuperView = [self.tableView.superview convertRect:[UIScreen mainScreen].bounds 
                                                                     fromView:[UIApplication sharedApplication].keyWindow];
    CGFloat bottomOffset = CGRectGetMaxY(screenRectInTableSuperView) - CGRectGetMaxY(self.tableView.frame);
    self.tableView.frame = TTRectContract(self.tableView.frame, 0, bounds.size.height - bottomOffset);
    [self.tableView scrollFirstResponderIntoView];
}

///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)keyboardWillDisappear:(BOOL)animated withBounds:(CGRect)bounds {
    [super keyboardWillDisappear:animated withBounds:bounds];
    
    if (_tableView) {
        CGRect previousFrame = self.tableView.frame;
        self.tableView.height = self.view.height;
        
        if (self.tableView.height > self.view.bounds.size.height) {
            self.tableView.frame = previousFrame;
        }
    }
}

 

原文:https://github.com/jeanregisser/three20/commit/026c9a65f1d91625e42cb7ca60d5eb97cd543a0a

修复后的tttableviewcontroller.m

https://github.com/jeanregisser/three20/blob/026c9a65f1d91625e42cb7ca60d5eb97cd543a0a/src/Three20UI/Sources/TTTableViewController.m

posted @ 2012-06-08 14:22  alex hu  阅读(314)  评论(0编辑  收藏  举报