2013-10-16 10 views
6

se ruoto il dispositivo Mentre collectionview esegueBatchUpdate con reloadItemsAtIndexPaths, la vista di raccolta si troverà male. ma la vista rimarrà comunque in una posizione costante.UICollectionView performBatchUpdates causa errore di visualizzazione della collezione durante la rotazione del dispositivo

Per risolvere semplicemente il problema:

setting [UIView setAnimationEnabled: NO]; in willRotateToInterfaceOrientation 
+ 
setting [UIView setAnimationEnabled: YES]; in didRotateToInterfaceOrientation 

Ma non penso che questo è un buon modo per risolvere questo problema.

Qualcuno ha un'idea migliore?

Cheers.

Ecco il mio codice:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 
    NSLog(@"Before Rotation"); 
    NSLog(@"collecitonview Rect : %@", NSStringFromCGRect(self.collectionView.frame)); 
    NSLog(@"view Rect : %@", NSStringFromCGRect(self.view.frame)); 
} 

    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ 
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 
    NSLog(@"After Rotation"); 
    NSLog(@"collecitonview Rect : %@", NSStringFromCGRect(self.collectionView.frame)); 
    NSLog(@"view Rect : %@", NSStringFromCGRect(self.view.frame)); 
} 

    - (void) viewDidAppear:(BOOL)animated{ 
    [super viewDidAppear:animated]; 
    for(int i = 0 ; i < 30; i++){ 
     NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{ 
      CGFloat hue = arc4random() % 20; 
      [self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:hue inSection:0]]]; 
     }]; 
     [_operationsArray addObject:operation]; 
    } 
    [self performUpdate]; 
} 

    - (void)performUpdate{ 

    if(_operationsArray.count == 0)return; 

    [self.collectionView performBatchUpdates:^{ 
     NSBlockOperation *operation = (NSBlockOperation*)[_operationsArray firstObject]; 
     [operation start]; 
    } completion:^(BOOL finished) { 
     if(_operationsArray.count != 0){ 
      [_operationsArray removeObjectAtIndex:0]; 
      [self performUpdate]; 
     } 
    }]; 
} 

l'output: (se ho ruotato il dispositivo durante eseguire l'aggiornamento)

2013-10-16 17:05:18.445 collectionviewbatchupdateTest[90419:a0b] Before Rotation 
2013-10-16 17:05:18.446 collectionviewbatchupdateTest[90419:a0b] collecitonview Rect : {{0, 0}, {1024, 768}} 
2013-10-16 17:05:18.446 collectionviewbatchupdateTest[90419:a0b] view Rect : {{0, 0}, {768, 1024}} 
2013-10-16 17:05:18.851 collectionviewbatchupdateTest[90419:a0b] After Rotation 
2013-10-16 17:05:18.851 collectionviewbatchupdateTest[90419:a0b] collecitonview Rect : {{-128, 0}, {1024, 1024}} 
2013-10-16 17:05:18.852 collectionviewbatchupdateTest[90419:a0b] view Rect : {{0, 0}, {768, 1024}} 
+0

Qualsiasi fortuna con questo? – lupinglade

risposta

0

Stesso problema qui. Sembra un bug in UICollectionView. L'unica soluzione alternativa che è stato possibile trovare è ripristinare la cornice della vista dell'insieme dopo la rotazione.

Succede in tutti gli aggiornamenti batch durante la rotazione sembra, non solo reloadItemsAtIndexPaths.

0

sto manipolazione di questo re-rispettare telaio della vista collezione dopo la rotazione:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    self.collectionView.frame = self.view.bounds; 
} 
0

Sembra essere un problema di UICollectionView. Il mio suggerimento è di impostare il fotogramma dopo l'esecuzione di BatchUpdate

CGRect frame = self.collectionView.frame; 
[self.collectionView performBatchUpdates:^{ 
     NSBlockOperation *operation = (NSBlockOperation*)[_operationsArray firstObject]; 
     [operation start]; 
    } completion:^(BOOL finished) { 
     if(_operationsArray.count != 0){ 
      [_operationsArray removeObjectAtIndex:0]; 
      [self performUpdate]; 
     } 
     if(CGRectEqualToRect(self.collectionView.frame, frame)) 
     { 
      [self.collectionView setFrame:frame]; 
     } 
    }]; 
Problemi correlati