0

I am trying all the stuffs i could like using UIView to animate but in vain. I need the CollectionView Cells should automatically swipe horizontally after every fixed seconds.

Please help me out with this, as this is the only sole reason my app is waiting its release.

I tried this but in vain.

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    if (collectionView == self.myCV) {
        myCollectionView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath];

        if (cell == nil)
        {

            NSArray *xibPath = [[NSBundle mainBundle] loadNibNamed:@"myCollectionView" owner:self options:nil];
            cell = [xibPath objectAtIndex:0];
        }

//        [myCV performBatchUpdates:^{
//            [self.myCV reloadData];
//        } completion: nil];
        [UIView animateWithDuration:0.3f delay:0.0 options:0 animations:^{
            [self.myCV scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:indexPath.section inSection:0]
                                        atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
                                                animated:NO];
        } completion:^(BOOL finished) {
            NSLog(@"Completed");
        }];

        return cell;



    }

Thank You, *Best Regards.*

  • You mean the left most cells disappear and new ones appear on the right ? – paul Aug 12 '13 at 11:51
  • how many cell visible in your uicollectionview ? – iPatel Aug 12 '13 at 12:01
  • @paul : Exactly !!! If you need i can send a demo for the same to have you feel the need. –  Aug 12 '13 at 12:01
  • @iPatel : Those are coming from webService. Dynamic –  Aug 12 '13 at 12:01
  • but by default if you do not scroll then maximum how many ?? – iPatel Aug 12 '13 at 12:03
  • @iPatel : initially one cell would be displayed.Then after one second another would come in picture as in we have swipe it horizontally. The idea is to make the cells swipe automatically in horizontal direction. –  Aug 12 '13 at 12:04
  • @iPatel : If you need, i can send you a demo copy for the same. –  Aug 12 '13 at 12:09

2 Answers2

3

If your move code is working then use it in timer function with interval of 1 sec as

[NSTimer scheduledTimerWithTimeInterval:1.0
                                 target:self
                               selector:@selector(targetMethod)
                               userInfo:nil
                                repeats:YES];

-(void)targetMethod
{

    [self.myCV scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:rowIndex inSection:0]
                      atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally
                              animated:YES];

    rowIndex=(rowIndex<noOfRows-1)?(rowIndex+1):0;

}

OR

This could help u better

https://stackoverflow.com/a/13129472/1305001

Community
  • 1
  • 1
Warewolf
  • 12,416
  • 4
  • 55
  • 85
0

You should wrap insert/delete/reload operations in a performBatchUpdates:completion: block. eg :

[collectionView performBatchUpdates:^{
    [self.collectionView reloadData];
} completion: nil];

You should then use a timer to call this code periodically. This assumes you also update your data source

paul
  • 1,112
  • 9
  • 15
  • Probably this would reload data. Do i need to include a timer in it. I have never face d animations or timer.Please elaborate –  Aug 12 '13 at 12:34
  • Hey i did use the above code in my demo app, but the thing is the app is not launching at all. –  Aug 12 '13 at 12:37
  • You need to periodically call this code with an NSTimer. It should call collectionView:cellForItemAtIndexPath: automatically – paul Aug 12 '13 at 13:36