2013-02-06 10 views
11

क्या [table beginUpdates]/[table endUpdates] एनिमेशन की अवधि बदलने का कोई तरीका है?UITableView एनीमेशन की अवधि बदलें (तालिका प्रारंभ के साथ पंक्तियां डालें/हटाएं)

विकल्प 1::

[UIView animateWithDuration:5.0 delay:0.0 options:(UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionOverrideInheritedDuration) animations:^{ 

    [self.tableView beginUpdates]; 

    [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithArray:indexPaths] withRowAnimation:UITableViewRowAnimationTop]; 

    [self.tableView endUpdates]; 


} completion:^(BOOL finished) { 
}]; 

विकल्प 2:

[CATransaction begin]; 

[CATransaction setCompletionBlock:^{ 
    NSLog(@"I actually get called!"); 
}]; 

[CATransaction setAnimationDuration:5.0]; //but I don't work 

[self.tableView beginUpdates]; 

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithArray:indexPaths] withRowAnimation:UITableViewRowAnimationTop]; 

[self.tableView endUpdates]; 

[CATransaction commit]; 
+0

इस सवाल का चेक आउट: http://stackoverflow.com/questions/3832474/uitableview-row-animation-duration-and-completion-callback/13041475#13041475 यह CATransaction का उपयोग करता है को प्राप्त करने के आप क्या चाहते हैं: -) –

+0

मैंने यह प्रश्न देखा है। यह काम करेगा, लेकिन मेरी समस्या यह है कि मुझे विशेष रूप से अवधि की आवश्यकता है, जो काम नहीं करता है। आईई, इस प्रश्न में विकल्प 2 में, मुझे लाइन '[CATransaction setAnimationDuration: 5.0];' काम करने की आवश्यकता है और यह नहीं है। –

+0

@TomRedman कभी भी इस समस्या के लिए एक अच्छा समाधान मिलता है? मैं उपरोक्त बेन से जुड़े प्रश्न में देखता हूं कि अब ऐसा लगता है जो आईओएस 7 में काम करता है, लेकिन 6 नहीं ... –

उत्तर

11

क्यों नहीं कर

यह है कि मैं क्या कोई भाग्य के साथ, की कोशिश की है है आप UIView एनीमेशन आज़माएं।

[UIView animateWithDuration:2 delay:0.2 options:UIViewAnimationOptionCurveEaseInEaseOut animations:^{ 
    [self.tableView beginUpdates]; 
    [self.tableView endUpdates]; 
} completion:^(BOOL finished) { 
    // code 
}]; 
+1

आईओएस 7 और आईओएस 8 पर मेरे लिए काम करता है! –

+0

यह एक उत्तर है! आईओएस 9 पर भी काम करता है। – silvansky

+0

आईओएस 9 में काम करता है लेकिन अन्य एनिमेशन अजीब काम करता है – Miniroo

1

@ गौतम जैन का समाधान बहुत अच्छा है। हालांकि, कम से कम आईओएस 9 में यह एक समस्या है: समापन ब्लॉक एक बार में निष्पादित किया जाएगा, लेकिन जब एनीमेशन पूर्ण नहीं होता है।

मैं आमतौर पर थोड़ा और कोड के साथ नीचे की तरह करता हूं लेकिन बेहतर काम करता है।

[UIView beginAnimations:@“animation” context:nil]; 
[UIView setAnimationDuration:0.25]; 
[CATransaction begin]; 
[CATransaction setCompletionBlock:^{ 
    // completion block 
}]; 

[self.tableView beginUpdates]; 
// updates 
[self.tableView endUpdates]; 

[CATransaction commit]; 
[UIView commitAnimations]; 
संबंधित मुद्दे