[英]How to check view scrollable position when scrollview scroll
We have implemented sticky out stream Ad functionality by using text view. 我们已使用文本视图实施了粘性流出广告功能。 When text view scroll we have show added one view in mid of text view text.
当文本视图滚动时,我们在文本视图文本的中间添加了一个视图。 And when textview scroll and added view is going out from view.
当textview滚动和添加的视图从视图中出来时。 then we have show another view with same content of added view.
然后我们显示另一个视图,其中添加了相同的视图内容。 It works perfect.
它完美无缺。 But now my new requirement is when user scroll the text view and added view appears.
但现在我的新要求是用户滚动文本视图并显示添加的视图。 Then we need to show the second added view according to view appearance.
然后我们需要根据视图外观显示第二个添加的视图。 like added view is only 50% appear on screen then we need to show the second view.
像添加的视图只有50%出现在屏幕上然后我们需要显示第二个视图。 Now my problem is how to detect the view appearance according to scroll position.
现在我的问题是如何根据滚动位置检测视图外观。 for hide or show view.
用于隐藏或显示视图。 Thanks in Advance
提前致谢
You have to use scrollViewDidScroll
delegate method for that. 您必须使用
scrollViewDidScroll
委托方法。 You can try with following: 您可以尝试以下方法:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
// Table View Scroll Image
let viewContentOffset = textview.contentOffset
let viewContentSize = textview.contentSize
let viewBounds = textview.bounds.size
// Use Alpha value to manipulation
let bottomOffset = scrollView.contentSize.height - scrollView.bounds.size.height
let alpha = (scrollView.contentOffset.y / bottomOffset) * 2
}
Add Image to TextView using NSAttributtedString: 使用NSAttributtedString将图像添加到TextView:
textView.text = "Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda."
let image = UIImage(named: "sampleImage.png");
let attachment = NSTextAttachment()
attachment.image = image
let attString = NSAttributedString(attachment: attachment)
textView.textStorage.insert(attString, at: textView.text.count/2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.