Search code examples
iosobjective-cswifticarousel

How to reload iCarousel with animation?


I tried to find a way of reloading the iCarousel with animations. Something like:

[self.carousel reloadDataAnimated:YES] // ObjC
self.carousel!.reloadData(animated: true) // Swift

I looked into the header and it looks like the control does not support this. Does anyone know how can I achieve a carousel reload with animation?


Solution

  • I found a way of doing this using transitionWithView method. Works like a charm. Carousel's content is reloaded with a nice cross dissolve animation. Here is the code:

    Swift

    UIView.transitionWithView(self.carousel!,
                              duration: 0.35,
                              options: .TransitionCrossDissolve,
                              animations: { () -> Void in
    
                                  self.carousel!.reloadData()
                              },
                              completion:nil)
    

    ObjC

    [UIView transitionWithView:self.carousel
                      duration:0.35f
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^(void)
     {
          [self.carousel reloadData];
     }
                    completion:nil];