Unikaj animacji UICollectionView po reloadItemsAtIndexPaths
UICollectionView elementy animate po przeładowaniu wywołane jest polecenie "fade animation".
Czy jest sposób na uniknięcie tej animacji?
IOS 6
8 answers
Możesz też spróbować tego:
UICollectionView *collectionView;
...
[UIView setAnimationsEnabled:NO];
[collectionView performBatchUpdates:^{
[collectionView reloadItemsAtIndexPaths:indexPaths];
} completion:^(BOOL finished) {
[UIView setAnimationsEnabled:YES];
}];
Edit:
Odkryłem również, że jeśli zawijasz performBatchUpdates
W blok animacji UIView, animacja UIView jest używana zamiast domyślnej animacji, więc możesz ustawić czas trwania animacji na 0, jak tak:
[UIView animateWithDuration:0 animations:^{
[collectionView performBatchUpdates:^{
[collectionView reloadItemsAtIndexPaths:indexPaths];
} completion:nil];
}];
To jest ekstra fajne, jeśli chcesz używać sprężystych animacji iOS 7 podczas wstawiania i usuwania!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-03-05 12:26:55
Warto zauważyć, że jeśli celujesz w iOS 7 i nowsze, możesz użyć nowej metody UIView
performWithoutAnimation:
. Podejrzewam, że pod maską robi to tak samo jak inne odpowiedzi tutaj (chwilowe wyłączenie UIView
animations / Core Animation actions), ale składnia jest ładna i czysta.
Więc na to pytanie w szczególności...
Objective-C:
[UIView performWithoutAnimation:^{
[self.collectionView reloadItemsAtIndexPaths:indexPaths];
}];
Swift:
UIView.performWithoutAnimation {
self.collectionView.reloadItemsAtIndexPaths(indexPaths)
}
Oczywiście zasada ta może być stosowana dla każdego sytuacji, że chcesz zapewnić zmianę jest Nie animowane.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-26 12:30:49
Napisałem kategorię na UICollectionView aby to zrobić. Trik polega na wyłączeniu wszystkich animacji podczas przeładowywania: {]}
if (!animated) {
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
}
[self reloadItemsAtIndexPaths:indexPaths];
if (!animated) {
[CATransaction commit];
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-19 10:56:37
Oto wersja Swift 3 do performBatchUpdates
bez animacji do UICollectionView
. Okazało się, że to działa lepiej dla mnie niż collectionView.reloadData()
, ponieważ zmniejszyło zamianę komórek podczas wstawiania rekordów.
func appendCollectionView(numberOfItems count: Int){
// calculate indexes for the items to be added
let firstIndex = dataItems.count - count
let lastIndex = dataItems.count - 1
var indexPaths = [IndexPath]()
for index in firstIndex...lastIndex {
let indexPath = IndexPath(item: index, section: 0)
indexPaths.append(indexPath)
}
UIView.performWithoutAnimation {
self.collectionView.performBatchUpdates({ () -> Void in
self.collectionView.insertItems(at: indexPaths)
}, completion: { (finished) -> Void in
})
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-31 09:46:08
- (void)reloadCollectionViewAnimated:(BOOL)animated {
if (animated) {
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:^(BOOL finished) {
}];
} else {
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
[CATransaction commit];
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-01-25 16:54:33
Aby dodać moje $0.02, próbowałem obu wersji wybranej odpowiedzi, a oryginalny sposób działał lepiej dla moich celów. Pracuję nad nieskończonym przewijaniem widoku kalendarza, który pozwala użytkownikowi wejść do kalendarza w danym tygodniu, a następnie przesuń palcem w przód iw tył i wybierz poszczególne dni do filtrowania listy.
W mojej implementacji, aby wszystko działało na starszych urządzeniach tablica dat reprezentująca widok kalendarza musi być stosunkowo mała co oznacza trzymanie dat o wartości 5 tygodni, z użytkownikiem w środku w 3 tygodniu. Problem z używaniem drugiego podejścia polega na tym, że jest drugi krok, w którym musisz przewijać widok kolekcji z powrotem do środka bez animacji, co sprawia, że z jakiegoś powodu blokowana animacja bazowa jest bardzo poszarpana.
Mój Kod:
[UIView setAnimationsEnabled:NO];
[self.collectionView performBatchUpdates:^{
[self.collectionView deleteItemsAtIndexPaths:indexPathDeleteArray];
[self.collectionView insertItemsAtIndexPaths:indexPathAddArray];
} completion:NULL];
[UIView setAnimationsEnabled:YES];
NSIndexPath *newIndexPath = [NSIndexPath indexPathForItem:14 inSection:0];
[self.collectionView scrollToItemAtIndexPath:newIndexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:NO];
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-06-08 01:56:42
Zakładam, że używasz FlowLayout. Ponieważ próbujesz pozbyć się animacji fade, spróbuj tego:UICollectionView elementy animate po przeładowaniu (fade animation).
Czy istnieje sposób, aby uniknąć tej animacji?
IOS 6
import UIKit
class NoFadeFlowLayout: UICollectionViewFlowLayout {
override func initialLayoutAttributesForAppearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attrs = super.initialLayoutAttributesForAppearingItem(at: itemIndexPath)
attrs?.alpha = 1.0
return attrs
}
override func finalLayoutAttributesForDisappearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let attrs = super.finalLayoutAttributesForDisappearingItem(at: itemIndexPath)
attrs?.alpha = 1.0
return attrs
}
}
To bardzo stare pytanie, więc prawdopodobnie nie celujesz już w iOS 6. Osobiście pracowałem nad tvOS 11 i miałem to samo pytanie, więc to jest tutaj dla każdego, kto przychodzi razem z tym samym problemem.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-09 03:07:49
extension UICollectionView {
func reloadWithoutAnimation(){
CATransaction.begin()
CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions)
self.reloadData()
CATransaction.commit()
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-01-03 07:21:36