स्विफ्ट 3 अभय एम और D6mi के जवाब के संस्करण:
स्क्रॉल उपयोगकर्ता के कारण होता है जब कार्रवाई
public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if (!decelerate) {
//cause by user
print("SCROLL scrollViewDidEndDragging")
}
}
public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
//caused by user
print("SCROLL scrollViewDidEndDecelerating")
}
जब स्क्रॉल कोड कार्रवाई के कारण होता है (प्रोग्राम के रूप में): ("scrollRectToVisible" या "scrollT की तरह oItemAtIndexPath ")
public func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
//caused by code
print("SCROLL scrollViewDidEndScrollingAnimation")
}
नोट्स:
- अपने UIScrollViewDelegate या UICollectionViewDelegate प्रतिनिधि में इन कार्यों रखो।
- यदि आप एक अलग प्रतिनिधि नहीं है, अपने वर्तमान वर्ग अपने वर्ग फ़ाइल
के UIScrollViewDelegate सेशन शीर्ष विस्तार कर सकते हैं।
open class MyClass: NSObject , UICollectionViewDelegate
और कहीं आपके viewWillAppear वर्ग का अपना प्रतिनिधि
override open func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// ...
self.myScrollView.delegate = self
// ...
}
शानदार बनाने में। आप नहीं जानते कि यह कितना बुरा कोड है जो मुझे बचाता है। मैं अपने UICollectionViewFlowLayout में callInvalidateLayoutForBoundsChange कॉलबैक का उपयोग करके इसे मॉनीटर करने की कोशिश कर रहा था। क्या एक n00b है। –
कृपया नीचे देखें D6mi का नोट scrollViewDidEndScrollingAnimation के बारे में। scrollViewDidEndDecelerating प्रोग्रामेटिक स्क्रॉलिंग के लिए नहीं बुलाया जाता है। – RajV
दरअसल, मुझे समझ में नहीं आता कि वर्तमान उत्तर स्वीकार्य क्यों है, यह काम नहीं करता है 'स्क्रॉल व्यूडिड एंड डिस्सेरेटिंग' को कॉल नहीं किया जाता है, लेकिन डी 6 एमआई ने कहा, 'scrollViewDidEndScrollingAnimation' को – AkademiksQc