如何让UIScrollView
开始从上到下滚动。当我向下滑动(向下)时,它将首先向下滚动而不是向上滚动并消失。我现在拥有的是,我可以先向上滚动然后向下滚动,向下滚动它会消失。
这是我的代码 -
func scrollViewDidScroll(_ scrollView: UIScrollView) {
//for toogle swipe view
if scrollView.contentOffset.y < 120 {
self.swipeMsgView.isHidden = false
}else {
self.swipeMsgView.isHidden = true
}
//for making bottom inset
if scrollView.contentOffset.y < 190 {
var contentInset:UIEdgeInsets = scrollView.contentInset
contentInset.bottom = scrollView.contentOffset.y-100
scrollView.contentInset = contentInset
}
//when swipe down
if scrollView.contentOffset.y == 0 {
if !isScrollDownFirstTime{
UIView.animate(withDuration: 0.5, animations: {
self.dismiss(animated: true, completion: nil)
})
}
}
//for tracking first time scrolling
if scrollView.contentOffset.y > 150 {
isScrollDownFirstTime = false
}
}
工作正常。但是我想在用户首先滑动或向下滚动时消失视图(滑动手势不起作用)。使用这个现有功能有没有优雅的方法呢?谢谢。
答案 0 :(得分:0)
@Serg Smyk,这是我解决问题的方法。
fileprivate var isScrollDownFirstTime = true
func scrollViewDidScroll(_ scrollView: UIScrollView) {
print("Content y offet : \(scrollView.contentOffset.y)")
//for toogle swipe view
if scrollView.contentOffset.y < 120 {
self.swipeMsgView.isHidden = false
} else {
self.swipeMsgView.isHidden = true
}
//for making bottom inset
if scrollView.contentOffset.y < 190 {
var contentInset:UIEdgeInsets = scrollView.contentInset
contentInset.bottom = scrollView.contentOffset.y-100
scrollView.contentInset = contentInset
}
//when swipe down
if scrollView.contentOffset.y == 0 {
print(CLASS_NAME+" -- scrollViewDidScroll() -- contentOffset.y = 0")
if !isScrollDownFirstTime{
UIView.animate(withDuration: 0.5, animations: {
self.dismiss(animated: true, completion: nil)
})
}
}
if scrollView.contentOffset.y < 1 {
print(CLASS_NAME+" -- scrollViewDidScroll() -- contentOffset.y<0")
UIView.animate(withDuration: 0.5, animations: {
self.dismiss(animated: true, completion: nil)
})
}
//for tracking first time scrolling
if scrollView.contentOffset.y > 150 {
isScrollDownFirstTime = false
}
}