2013-10-16 6 views
6

यदि मैं डिवाइस को घुमाता हूं, संग्रह संग्रह निष्पादित करता है ReloadItemsAtIndexPaths के साथ बैचअपडेट, संग्रह दृश्य गुमराह हो जाएगा। लेकिन दृश्य अभी भी स्थिर स्थिति में रहेगा।UICollectionView performBatchUpdates डिवाइस को घुमाने के दौरान संग्रहदृश्य गलत जगह का कारण बनता है

सीधे शब्दों में इस मुद्दे को ठीक करने के लिए:

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

लेकिन मुझे लगता है यह इस समस्या को हल करने के लिए एक अच्छा तरीका है न।

क्या किसी को बेहतर विचार मिला है?

चीयर्स।

यहाँ मेरी कोड है:

- (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]; 
     } 
    }]; 
} 

उत्पादन: (मैं डिवाइस घुमाया अगर दौरान अद्यतन प्रदर्शन)

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

इसके साथ कोई भाग्य? – lupinglade

उत्तर

0

ही यहां मुद्दा यह है। यह UICollectionView में एक बग की तरह दिखता है। रोटेशन के बाद संग्रह दृश्य के फ्रेम को रीसेट करना एकमात्र अन्य कामकाज मुझे मिल सकता है।

यह रोटेशन के दौरान किसी भी बैच अपडेट में होता है, ऐसा लगता है कि यह केवल पुनः लोड नहीं है ItemsAtIndexPaths।

0

मैं रोटेशन के बाद फिर से लागू करने संग्रह दृश्य के फ्रेम द्वारा इस से निपटने हूँ:

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

यह एक UICollectionView मुद्दा हो रहा है। मेरा सुझाव है कि प्रदर्शन के बाद फ्रेम सेट करना है बैचअपडेट्स किया गया है

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]; 
     } 
    }]; 
संबंधित मुद्दे