Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. - (void)viewWillLayoutSubviews;
  2. {
  3. [super viewWillLayoutSubviews];
  4. UICollectionViewFlowLayout *flowLayout = (id)self.collectionView.collectionViewLayout;
  5.  
  6. if (UIDeviceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
  7. flowLayout.itemSize = CGSizeMake(1024.0f, 768.0f);
  8. } else {
  9. flowLayout.itemSize = CGSizeMake(1024.0f, 768.0f);
  10. }
  11.  
  12. [flowLayout invalidateLayout]; //force the elements to get laid out again with the new size
  13.  
  14. visibleItems = [self.collectionView indexPathsForVisibleItems];
  15. self.currentIndexPath = [visibleItems firstObject];
  16. [self.collectionView.collectionViewLayout invalidateLayout];
  17. }
  18.  
  19. - (IBAction)addToUploadQueque:(id)sender {
  20. NSLog(@"current: %@",self.currentIndexPath);
  21.  
  22. NSInteger section = [self numberOfSectionsInCollectionView:self.collectionView] - 1;
  23. NSInteger item = [self collectionView:self.collectionView numberOfItemsInSection:section]-1;
  24. NSIndexPath *lastIndexPath = [NSIndexPath indexPathForItem:item inSection:section];
  25. NSIndexPath *firstIndexpath =[NSIndexPath indexPathForItem:0 inSection:0];
  26.  
  27. NSLog(@"current: %@",lastIndexPath);
  28. if (self.currentIndexPath <= lastIndexPath) {
  29. NSInteger newLast = [self.currentIndexPath indexAtPosition:self.currentIndexPath.length-1]+1;
  30. self.currentIndexPath = [[self.currentIndexPath indexPathByRemovingLastIndex] indexPathByAddingIndex:newLast];
  31. [self.collectionView scrollToItemAtIndexPath:self.currentIndexPath
  32. atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
  33. animated:YES];
  34. }else{
  35. self.currentIndexPath = [visibleItems firstObject];
  36. [self.collectionView scrollToItemAtIndexPath:self.currentIndexPath
  37. atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
  38. animated:YES];
  39. }
  40.  
  41. }
  42.  
  43. NSInteger item = self.currentIndexPath.item;
  44. NSInteger section = self.currentIndexPath.section;
  45.  
  46. item++; // go to next item
  47. if (item >= [self.collectionView numberOfItemsInSection:section]) { // if you reached end of section ...
  48. item = 0; // ... go to the start of the next section
  49. section++;
  50. if (section >= [self.collectionView numberOfSections]) { // if you reached the end of the data source ...
  51. // all done, so set section to zero to go back to beginning, e.g. // ... then you're done
  52. section = 0;
  53. }
  54. }
  55. self.currentIndexPath = [NSIndexPath indexPathForItem:item inSection:section]; // otherwise, this is your new NSIndexPath
  56.  
  57. for (NSIndexPath *indexPath in self.collectionView.indexPathsForVisibleItems) {
  58. // if the cell has some visual indication to reflect upload has been initiated,
  59. // do that here
  60.  
  61. // do your asynchronous upload here, where the completion block dispatches
  62. // updates to the cell/collectionView (to reflect that the individual upload
  63. // is done)
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement