GSKStretchyHeaderView
GSKStretchyHeaderView copied to clipboard
UITableView Moves Down when UIKeyboard
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
after I press -
). Thanks in advance.
I've edited my issue. Sorry for bad pictures
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 :)
Does anyone know of a solution for this? The same behaviour happens with UICollectionView too
Hi,
Please give a try to the solution I suggested above, I think it should do the trick :)
Best regards
Hi, I am actually using a collectionview inside a view controller. But still facing the same issue.
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;
Yes, it's a little bit weird... Did you try using the header view in a plain UIViewController, as I suggested above?
I never use UITableViewController, only plain version
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.
}
}
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.