के साथ मैं तेजी से स्वीप, like this के बाद तेजी से स्क्रॉल करने के लिए UIScrollView चाहता हूं। हालांकि, जब पेजिंग चालू होती है, तो स्क्रॉल one page at a time काम करता है। क्या तेजी से स्क्रॉल करना संभव है, जब इशारा पहचानकर्ताओं का उपयोग करके मैन्युअल रूप से कार्यान्वित किए बिना उंगली की झटके से पेजिंग सक्षम हो?UIScrollView की संवेदनशीलता/स्क्रॉल गति पेजिंग
उत्तर
यह काफी सरल है, हालांकि आपको पेजिंग पहलू को स्वयं लागू करना होगा (जो काफी सरल है)। आपको इशारा पहचानकर्ताओं की आवश्यकता नहीं है।
स्विफ्ट
पहले, अपने UIScrollView मंदी दर को समायोजित:
scrollView.decelerationRate = UIScrollViewDecelerationRateFast
मान लें कि हम सामग्री की एक सरणी है - यह yourPagesArray
फोन करते हैं।
:
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)
{
//This is the index of the "page" that we will be landing at
let nearestIndex = Int(CGFloat(targetContentOffset.pointee.x)/scrollView.bounds.size.width + 0.5)
//Just to make sure we don't scroll past your content
let clampedIndex = max(min(nearestIndex, yourPagesArray.count - 1), 0)
//This is the actual x position in the scroll view
var xOffset = CGFloat(clampedIndex) * scrollView.bounds.size.width
//I've found that scroll views will "stick" unless this is done
xOffset = xOffset == 0.0 ? 1.0 : xOffset
//Tell the scroll view to land on our page
targetContentOffset.pointee.x = xOffset
}
आप निम्न प्रतिनिधि विधि को लागू करने, मामले को संभालने के लिए की आवश्यकता होगी, जहां उपयोगकर्ता किसी भी पुस्तक मंदी पैदा करने के बिना धीरे उनकी उंगली लिफ्टों: अपने UIScrollViewDelegate में, निम्न विधि को लागू (अद्यतन:।। आप नवीनतम आईओएस एसडीके के तहत ऐसा करने की जरूरत नहीं हो सकता है ऐसा लगता है ऊपर प्रतिनिधि विधि की तरह अब कहा जाता है जब वहाँ शून्य वेग)
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool)
{
if !decelerate
{
let currentIndex = floor(scrollView.contentOffset.x/scrollView.bounds.size.width)
let offset = CGPoint(x: scrollView.bounds.size.width * currentIndex, y: 0)
scrollView.setContentOffset(offset, animated: true)
}
}
ऑब्जेक्टिव-सी
अपने मंदी दर निर्धारित करना:
scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
फिर अपने स्क्रॉल दृश्य प्रतिनिधि कार्यान्वयन:
- (void) scrollViewWillEndDragging:(UIScrollView *)scroll withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
//This is the index of the "page" that we will be landing at
NSUInteger nearestIndex = (NSUInteger)(targetContentOffset->x/scrollView.bounds.size.width + 0.5f);
//Just to make sure we don't scroll past your content
nearestIndex = MAX(MIN(nearestIndex, yourPagesArray.count - 1), 0);
//This is the actual x position in the scroll view
CGFloat xOffset = nearestIndex * scrollView.bounds.size.width;
//I've found that scroll views will "stick" unless this is done
xOffset = xOffset==0?1:xOffset;
//Tell the scroll view to land on our page
*targetContentOffset = CGPointMake(xOffset, targetContentOffset->y);
}
- (void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if(!decelerate)
{
NSUInteger currentIndex = (NSUInteger)(scrollView.contentOffset.x/scrollView.bounds.size.width);
[scrollView setContentOffset:CGPointMake(scrollView.bounds.size.width * currentIndex, 0) animated:YES];
}
}
मुझे लगता है कि हम scrollView.userInteractionEnabled सेट कर सकते हैं = नहीं जब हमारे उंगली स्पर्श यह। और फिर जब एनीमेशन बंद हो जाता है, तो इसे खोलें। यह मेरे लिए काम करता है। आशा है कि यह आपकी मदद करेगा।
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
scrollView.userInteractionEnabled = NO;
}
// at the end of scroll animation, reset the boolean used when scrolls originate from the UIPageControl
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
scrollView.userInteractionEnabled = YES;
}
- 1. UIScrollView scrollRectToVisible कस्टम गति
- 2. UIScrollView क्षैतिज पेजिंग जैसे मोबाइल सफारी टैब
- 3. पेजिंग UIScrollView पड़ोसी पृष्ठों को देखकर
- 4. विभिन्न पेज चौड़ाई के साथ UIScrollView पेजिंग
- 5. "oversized" पृष्ठों के साथ एक पेजिंग UIScrollView कैसे बनाएं
- 6. गंतव्य सामग्री की गणना कैसे करें गति में UIScrollView की ऑफसेट
- 7. स्क्रॉलिंग की UIScrollView दिशा
- 8. फ़ाइल की सीमा गति। कॉपी
- 9. क्षैतिज लंबन स्क्रॉलिंग UIScrollView आईओएस
- 10. क्षैतिज पेजिंग
- 11. पेजिंग
- 12. पेजिंग
- 13. पेजिंग
- 14. पेजिंग
- 15. scrollViewWillEndDragging: withVelocity: targetContentOffset: UISCrollView
- 16. UIScrollView
- 17. प्रोसेसर की वर्तमान गति
- 18. सीएसएस की गति
- 19. घड़ी की गति
- 20. सी # सूचियों की गति
- 21. UIScrollView
- 22. UIScrollView
- 23. UIScrollView
- 24. UIScrollView
- 25. UIScrollView
- 26. UIScrollView
- 27. UIScrollView
- 28. UIScrollView
- 29. UIScrollView
- 30. UIScrollView
कभी इसका समाधान ढूंढें? – Eric
मेरी इच्छा है कि इसका कोई अच्छा समाधान हो। ऐसा लगता है कि इसे कार्यान्वित करने के दो तरीके हैं: मैन्युअल पहचानकर्ताओं को मैन्युअल रूप से कार्यान्वित करना या मैन्युअल रूप से कार्यान्वयन पेजिंग। – UrK
हां यह संभव है कि मैंने 6 महीने से पहले लागू किया था। आप मैन्युअल रूप से इशारा पहचानकर्ता बन सकते हैं .. – JohnWhite