Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UITableView Moves Down when UIKeyboard #38

Open
abusetrouble opened this issue Jan 6, 2017 · 10 comments
Open

UITableView Moves Down when UIKeyboard #38

abusetrouble opened this issue Jan 6, 2017 · 10 comments

Comments

@abusetrouble
Copy link

abusetrouble commented Jan 6, 2017

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
Copy link
Author

I've edited my issue. Sorry for bad pictures

@gskbyte
Copy link
Owner

gskbyte commented Jan 19, 2017

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 :)

@suyashb734
Copy link

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

@gskbyte
Copy link
Owner

gskbyte commented Feb 8, 2017

Hi,

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

Best regards

@suyashb734
Copy link

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

@abusetrouble
Copy link
Author

abusetrouble commented Feb 21, 2017

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;

@gskbyte
Copy link
Owner

gskbyte commented Feb 21, 2017

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

@abusetrouble
Copy link
Author

I never use UITableViewController, only plain version

@miserya
Copy link

miserya commented Jan 3, 2018

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.
    }
}

@ahdidou-mohamed
Copy link

ahdidou-mohamed commented May 21, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants