Snažím sa implementovať formulár výrazov &Podmienka, na ktorej je tlačidlo "Pokračovať" povolené iba po prechode do dolnej časti UITextView. Zatiaľ som nastavil svoju triedu ako delegát UIScrollView a implementoval nižšie uvedenú metódu:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"Checking if at bottom of UITextView");
CGPoint bottomOffset = CGPointMake(0,self.warningTextView.frame.size.height);
//if ([[self.warningTextView contentOffset] isEqualTO:bottomOffset])
{
}
}
Komentoval som príkaz if, pretože si nie som istý, ako skontrolovať, či je UITextView v dolnej časti. Má niekto nejaké návrhy?
Veľká vďaka, james
odpovede:
13 pre odpoveď č. 1UITextView je podtrieda UIScrollView. Preto používate metódu delegátov UIScrollView, ktorú používate aj pri použití UITextView.
Namiesto použitia scrollViewDidEndDecelerating
, mali by ste používať scrollViewDidScroll
, pretože scrollview môže zastaviť rolovanie bez spomalenia.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height)
{
NSLog(@"at bottom");
}
}
1 pre odpoveď č. 2
Verzia Swift pre túto otázku:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
print( "View scrolled to the bottom" )
}
}
0 pre odpoveď č. 3
Toto by malo riešiť. Funguje to. Používam ho.
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
float bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height;
if (bottomEdge >= scrollView.contentSize.height)
{
// we are at the end
}
}