检测UITextView滚动位置 [英] Detect UITextView scroll location

查看:164
本文介绍了检测UITextView滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现一个条款的形式,条件页面,其中继续按钮仅在用户滚动到UITextView的底部时启用。到目前为止,我已经将我的类设置为UIScrollView委托&已实施以下方法:

   - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 
{
NSLog(@检查是否在UITextView的底部);
CGPoint bottomOffset = CGPointMake(0,self.warningTextView.frame.size.height);
// if([[self.warningTextView contentOffset] isEqualTO:bottomOffset])
{
}
}

我已经评论了if语句,因为我不知道如何检查UITextView是否在底部。有人有任何建议吗?



非常感谢,
James

解决方案>

UITextView是一个UIScrollView子类。因此,使用UITextView时,您所使用的UIScrollView委托方法也可用。



而不是使用 scrollViewDidEndDecelerating 使用 scrollViewDidScroll ,因为scrollview可能会停止滚动而不减速。

  (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{
if(scrollView.contentOffset.y> = scrollView.contentSize.height - scrollView.frame.size.height)
{
NSLog(@at bottom);
}
}


I am trying to implement a form of a Terms & Conditions page where the "Proceed" button is only enabled once the user has scrolled to the bottom of a UITextView. So far I have set my class as a UIScrollView delegate & have implemented the method below:

- (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])
    {
    }    
}

I have commented the if statement because I am not sure how to check if the UITextView is at the bottom. Does anyone have any suggestions?

Many thanks, James

解决方案

UITextView is a UIScrollView subclass. Therefore the UIScrollView delegate method you are using is also available when using UITextView.

Instead of using scrollViewDidEndDecelerating, you should use scrollViewDidScroll, as the scrollview may stop scrolling without deceleration.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height)
    {
        NSLog(@"at bottom");
    }
}

这篇关于检测UITextView滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆