2012-03-29 14 views
8

जब मैं UITableView में एक पंक्ति का चयन करता हूं, तो मैं पंक्ति के फ्रेम के जीसीआरईटी पर scrollRectToVisible:animated पर कॉल कर रहा हूं, और तुरंत बाद में कुछ अन्य एनिमेशन कर रहा हूं। मेरी समस्या यह है कि मुझे नहीं पता कि scrollRectToVisible:animated से एनीमेशन कब पूरा हो गया है।एक UITableView में, मुझे कैसे पता चलेगा जब scrollRectToVisible एक पंक्ति के लिए पूर्ण हो गया है?

मेरे कोड:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView cellForRwoAtIndexPath:indexPath]; 

    [self.tableView scrollRectToVisible:cell.frame animated:YES]; 

    //more animations here, which I'd like to start only after the previous line is finished! 
} 
+0

+1 अच्छा सवाल है, लेकिन मुझे डर है कि जवाब है: आपको नहीं पता कि 'scrollRectToVisible: एनिमेटेड:' समाप्त होता है। – Sam

+0

निम्न प्रश्न का उत्तर यहां भी मदद कर सकता है: http://stackoverflow.com/questions/7198633/how-can-i-tell-when-a-uitableview-animation-has-finished – fishinear

उत्तर

3

प्रोटोकॉल UITableViewDelegateUIScrollViewDelegate के अनुरूप है। जब आप मैन्युअल रूप से स्क्रॉल आप BOOL पैरामीटर सेट कर सकते हैं और अधिक से scrollViewDidScroll:

BOOL manualScroll; 
... 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView cellForRwoAtIndexPath:indexPath]; 

    manualScroll = YES; 
    [self.tableView scrollRectToVisible:cell.frame animated:YES]; 
} 
... 
- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
    if (manualScroll) 
    { 
     manualScroll = NO; 
     //Do your staff 
    } 

} 

में यह जाँच मत भूलना UITableViewDelegate स्थापित करने के लिए।

+0

यह बहुत हैकी है, लेकिन ऐसा लगता है जैसे यह काम करेगा, और फ्रेमवर्क के बाद आप सबसे अच्छा कर सकते हैं। जवाब के लिए धन्यवाद! –

+0

UIScrollView पर 'ड्रैगिंग' संपत्ति है जो आपके लिए मैन्युअल स्क्रॉल ट्रैकिंग –

15

मैं इस UIScrollViewDelegate विधि भर में भाग गया:

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView 
{ 
    // Do your stuff. 
} 

केवल एनिमेटेड स्क्रॉल का आह्वान किया। स्पर्श-आधारित स्क्रॉल के लिए नहीं कहा जाता है। महान काम करने लगता है।

+0

बस जो मैं ढूंढ रहा था, धन्यवाद !! –

5

एक आसान तरीका इस तरह, एक UIView animateWith [...] ब्लॉक में स्क्रॉल कोड संपुटित के लिए है:

[UIView animateWithDuration:0.3f animations:^{ 
    [self.tableView scrollRectToVisible:cell.frame animated:NO]; 
} completion:^(BOOL finished) { 
    // Some completion code 
}]; 

ध्यान दें कि एनिमेटेड == नहीं scrollRectToVisible में: एनिमेटेड: विधि।

+0

यह anwser होना चाहिए –

संबंधित मुद्दे