如何找出 UITextview 中的文本不需要在 iOS 中滚动

问题描述

我在 UITextView 中显示条款和条件。当用户到达 UITextView 中文本的最后一行,然后只启用屏幕底部可用的按钮(导航到下一个屏幕)时。

我已经使用文本视图委托实现了所需的逻辑。

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
        float scrollViewHeight = scrollView.frame.size.height;
        float scrollContentSizeHeight = scrollView.contentSize.height;
        float scrollOffset = scrollView.contentOffset.y;

        if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
        {   // login to enable the button 
        }
    
}

此逻辑运行良好,但在 ipad Pro 设备中这会导致问题。 ipad pro 屏幕大,无需滚动即可看到所有文字

如何在不滚动的情况下找出 UITextView 中可见的文本。还有如何处理ipad Pro的问题。

解决方法

例如,在 if 中添加以下 viewDidLoad 语句。 (假设您的 UITextView 在这里称为 textView

 if (self.textView.contentSize.height <= self.textView.frame.size.height) {
     // Enable the continue button.
 }

因为只有在内容可能完全可见时才会出现在这里。由于不需要,当然不会调用 scrollViewDidScroll:

希望能帮到你