2015-11-04 12 views
5

पर फोकस ट्रिगर स्क्रॉलिंग अक्षम करें क्या सेल पर ध्यान केंद्रित होने पर UICollectionView की स्वत: स्क्रॉलिंग को अक्षम करने का कोई तरीका है? जब मैं फोकस में आता हूं तो मैं मैन्युअल रूप से सेल की सामग्री ऑफसेट को समायोजित करना चाहता हूं।UICollectionView

- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context 
     withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator 
{ 
    [coordinator addCoordinatedAnimations:^ 
    { 
     [UIView animateWithDuration:[UIView inheritedAnimationDuration] 
          animations:^ 
      { 
       // Move next focused cell. 
       if ([context.nextFocusedView isKindOfClass:[YBZEventCollectionViewCell class]]) 
       { 
        UICollectionViewCell *cell = (UICollectionViewCell *)context.nextFocusedView; 

        CGPoint offset = CGPointMake(CGRectGetMinX(cell.frame), 0.0f); 

        [_collectionView setContentOffset:offset]; 
       } 
      }]; 

    } completion:nil]; 
} 

यह काम करता है लेकिन जब से ध्यान देने के इंजन भी मेरे सेल ले जाता है (स्क्रॉल यह) मैं एनीमेशन जो चिकनी नहीं है के साथ खत्म हो, वहाँ है एक:

मैं सामग्री को अद्यतन करने में ऑफसेट wan't इसके अंत में "किक"।

उत्तर

-1

मुझे नहीं पता कि आप 'स्वचालित स्क्रॉलिंग' के साथ क्या मतलब रखते हैं, लेकिन संग्रह दृश्य कक्ष को बदलने के लिए आप अपने कस्टम सेल क्लास में didUpdateFocusInContext का उपयोग कर सकते हैं।

override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) { 
    coordinator.addCoordinatedAnimations({ [unowned self] in 
     if self.focused { 
      self.titleTopConstraint.constant = 27 

      self.titleLabel.textColor = UIColor.whiteColor() 
     } else { 
      self.titleTopConstraint.constant = 5 

      self.titleLabel.textColor = UIColor(red: 100/255, green: 100/255, blue: 100/255, alpha: 1) 
     } 
     self.layoutIfNeeded() 
    }, completion: nil) 
} 

या यदि आप एक कस्टम सेल नहीं है, UICollectionViewDelegate से didUpdateFocusInContext का उपयोग करें।

func collectionView(collectionView: UICollectionView, didUpdateFocusInContext context: UICollectionViewFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) { 
    coordinator.addCoordinatedAnimations({() -> Void in 
     if let indexPath = context.nextFocusedIndexPath, let cell = collectionView.cellForItemAtIndexPath(indexPath) { 
      // the cell that is going to be focused 
     } 
     if let indexPath = context.previouslyFocusedIndexPath, let cell = collectionView.cellForItemAtIndexPath(indexPath) { 
      // the cell that is going to be unfocused 
     } 
    }, completion: nil) 
} 
+0

क्षमा करें, मैं तुम्हें मेरे सवाल का गलत समझा लगता है। मैंने कुछ और कोड पोस्ट किया। मुझे एक संग्रह दृश्य होना है जो एक सेल से दूसरे सेल पर फोकस करते समय स्वचालित रूप से सामग्री ऑफसेट को अपडेट नहीं करता है। मैं सामग्री को अपने आप मैन्युअल रूप से मैनिपुलेशन ऑफसेट करना चाहता हूं। – RaffAl

-1

UICollectionView उपवर्गों के बाद से UIScrollView, अपने संग्रह को देखने के प्रतिनिधि स्क्रॉल दृश्य प्रतिनिधि तरीकों को लागू कर सकते हैं। एक तो आप शायद चाहते हैं:

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView 
       withVelocity:(CGPoint)velocity 
      targetContentOffset:(inout CGPoint *)targetContentOffset 

targetContentOffset स्क्रॉल ऑफसेट कि UIKit डिफ़ॉल्ट रूप से करने के लिए स्क्रॉल होगा, लेकिन अगर आप मूल्य बदल तो UIKit वहाँ के बजाय स्क्रॉल करेगा।

यदि आप सचमुच सचमुच यूआईकिट को अपने लिए किसी भी स्वचालित स्क्रॉलिंग नहीं करना चाहते हैं, तो आप हमेशा scrollEnabled को NO पर सेट करके पूरी तरह से स्क्रॉलिंग अक्षम कर सकते हैं।

1

बस इस सटीक चीज़ में भाग गया। एक UICollectionView का स्वत: स्क्रॉल अक्षम करने के लिए जब फोकस बदल जाता है, बस इंटरफ़ेस बिल्डर में संग्रह को देखने के लिए 'पत्रिका देखें' गुण में स्क्रॉल अक्षम:

enter image description here