GSKStretchyHeaderView icon indicating copy to clipboard operation
GSKStretchyHeaderView copied to clipboard

UITableView Moves Down when UIKeyboard

Open abusetrouble opened this issue 8 years ago • 10 comments

Hello, thanks for this awesome control! But I have a problem (could be represented in your Example app). If I have an UITextField inside custom subclass of GSKStretchyHeaderView. When UITextField becomes first responder - the table view moves down (The initial State is 2017-01-09 11 16 11 after I press -
2017-01-09 11 16 19 ). Thanks in advance.

abusetrouble avatar Jan 06 '17 17:01 abusetrouble

I've edited my issue. Sorry for bad pictures

abusetrouble avatar Jan 09 '17 07:01 abusetrouble

Hi, sorry for the (very) late and incomplete answer, but I've been super busy the last two weeks... And it doesn't seem to change soon.

I have detected that the contentInset.top changes abruptly after the keyboard is shown. This behaviour is like this by default in UITableViewController and it seems it can't be disabled easily. Another solution could be not to use an UITableViewController but an UIController with a UITableView instead. Or observing changes in contentInset, but that would increase the complexity of the view too much in my opinion.

Please let me know if this works for you :)

gskbyte avatar Jan 19 '17 07:01 gskbyte

Does anyone know of a solution for this? The same behaviour happens with UICollectionView too

suyashb734 avatar Feb 08 '17 06:02 suyashb734

Hi,

Please give a try to the solution I suggested above, I think it should do the trick :)

Best regards

gskbyte avatar Feb 08 '17 08:02 gskbyte

Hi, I am actually using a collectionview inside a view controller. But still facing the same issue.

suyashb734 avatar Feb 08 '17 08:02 suyashb734

Sorry for later corresponding. I have to use some strange code to fix this: For example Storing an instance variable @property (nonatomic, assign) BOOL isScrollViewDraggingManually; when I dragging myself.

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    self.isScrollViewDraggingManually = YES;
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.isScrollViewDraggingManually = NO;
    });
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if ([self.headerView.searchTextField isFirstResponder]) {
        if (scrollView == self.tableView && !self.isScrollViewDraggingManually) {
            CGFloat maxHeight = 124.f;
            if (scrollView.contentOffset.y < -maxHeight) {
                scrollView.contentOffset = CGPointMake(0.f, -maxHeight);
            }
        }
    }
}

And If I don't drag by myself - don't let set the offset

And when Keyboard will show (via NSNotification) I set up self.tableView.scrollEnabled = NO;

abusetrouble avatar Feb 21 '17 11:02 abusetrouble

Yes, it's a little bit weird... Did you try using the header view in a plain UIViewController, as I suggested above?

gskbyte avatar Feb 21 '17 18:02 gskbyte

I never use UITableViewController, only plain version

abusetrouble avatar Feb 22 '17 10:02 abusetrouble

I found solution: declare a TableView class, inherited from UITableView and implement there method scrollRectToVisible(_ rect:, animated:) with no implementation:

final class TableView: UITableView {
    override func scrollRectToVisible(_ rect: CGRect, animated: Bool) {
        // Don'd do anything here to prevent autoscrolling.
    }
}

miserya avatar Jan 03 '18 09:01 miserya

Thanks @miserya Tweak tested and it works . Another solution is to clear the Datasource when the Textfield becomes FirstResponder. But I prefer the implementation you've suggested.

ahdidou-mohamed avatar May 21 '18 15:05 ahdidou-mohamed