Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示可滚动项目Objective-C_Objective C_Scroll_Uitextview - Fatal编程技术网

显示可滚动项目Objective-C

显示可滚动项目Objective-C,objective-c,scroll,uitextview,Objective C,Scroll,Uitextview,对于我的应用程序,我有一个UITextView,当有可滚动的内容时,我需要显示一个箭头 当您处于底部或无法滚动文本时,图像必须隐藏 - (void)scrollViewDidScroll:(UIScrollView *)scrollView { self.scrollableItem.hidden = YES; float scrollViewHeight = scrollView.frame.size.height; float scrollContentSizeHeigh

对于我的应用程序,我有一个UITextView,当有可滚动的内容时,我需要显示一个箭头

当您处于底部或无法滚动文本时,图像必须隐藏

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

   self.scrollableItem.hidden = YES;
   float scrollViewHeight = scrollView.frame.size.height;
   float scrollContentSizeHeight = scrollView.contentSize.height;
   float scrollOffset = scrollView.contentOffset.y;

   if (scrollOffset > 0 && scrollOffset <= scrollViewHeight / 2) {
    self.scrollableItem.hidden = NO;
   } else if (scrollOffset <= 0 && scrollContentSizeHeight >= scrollViewHeight) {
    self.scrollableItem.hidden = NO;
   }
}
-(无效)scrollViewDidScroll:(UIScrollView*)scrollView{
self.scrollableItem.hidden=是;
浮动scrollViewHeight=scrollView.frame.size.height;
float scrollContentSizeHeight=scrollView.contentSize.height;
float scrollOffset=scrollView.contentOffset.y;

如果(scrollOffset>0&&scrollOffset您的思路是正确的。我们只需要一个公式来描述所需的条件:有太多的文本,这些文本延伸到视图底部以下

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView != self.textView) return;
    [self updateScrollableItem:(UITextView *)scrollView];
}

- (void)textViewDidChange:(UITextView *)textView {
    [self updateScrollableItem:textView];
}

- (void)updateScrollableItem:(UITextView *)textView {
    CGSize contentSize = textView.contentSize;
    CGSize boundsSize = textView.bounds.size;
    CGFloat contentOffsetY = textView.contentOffset.y;

    BOOL excess = contentSize.height > boundsSize.height;
    // notice the little fudge to make sure some portion of a line is above the bottom
    BOOL bottom = contentOffsetY + textView.font.lineHeight * 1.5 > contentSize.height - boundsSize.height;

    self.scrollableItem.hidden = !excess || bottom;
}

这是因为,对于给定字体,视图高度可能不是行高度的整数倍。多行一点似乎就可以了。

效果很好!谢谢!