1
votes

i use iCarousel lib as a scroll view for my app. The purpose of that library is to manage auto scrolling images. Image is set as a bounds of iCarousel class (which is actually UIView. It work fine, when initially loaded, but when i rotate device, it output odd bug. For example if i swipe from portrait to landscape, for fraction of second we can see following: enter image description here

Then:enter image description here

For some reason we see "old" pictures

Here is how i declare main method for displaying views:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view {



    NewScrollerItemForIPad *item;



    NewsItemMdl *mdl = self.viewModel.arrNews[index];
    if(mdl){

        /* Check for orientation */
        BOOL _isPortrait;

        if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){
            _isPortrait = NO;
        } else {
            _isPortrait = YES;
        }

        if (self.gotNews){

        if(!item){
            item = [[NewScrollerItemForIPad alloc] initWithFrame:car.bounds andOrientation:_isPortrait]; 
        }
        [item bindViewModel:mdl];
        }
    }
    return item;

}

And auto scrolling method:

-(void)runMethod{

    if(self.sliderCount== (self.pageControl.numberOfPages-1)){

        NSLog(@"Here we call");
        self.pageControl.currentPage = 0;
        self.sliderCount = 0;

        [car scrollToItemAtIndex:self.sliderCount animated:YES];

    }else{
        NSLog(@"And here we call");
        self.sliderCount++;
        self.pageControl.currentPage ++;
        [car scrollToItemAtIndex:self.sliderCount animated:YES];
    }

}

How to fix that bug? Obviously i dont want to future and old image to be loaded between new.

1
I'm not sure it is a feature or a bug in iCarousel, but I can tell you its implementation and behaviour are very-very odd (mostly buggy) – what we did to resolve the problems after orientation has changed we invoke the –reloadData method on the actual iCarousel instance every occasion.holex
@holex i did call [car reloadData]; in - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {, but unfortunnately problem isnt dissapear.Evgeniy Kleban
it would not really help on you if you reload the data before the actual rotation happens; you need to do it after.holex
@holex okay, i'll try, thank you!:)Evgeniy Kleban
@EvgeniyKleban I also have the same problem with iCarousel. When I run reloadData after screen was rotated I can see old size of carousel for a second. It looks not so pretty. Could you tell me please how did you solve this problem? Maybe you should add your your answer to this question.Roman Podymov

1 Answers

0
votes

Language: Swift

Reload the Carousel view as follows:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)
    coordinator.animate(alongsideTransition: { _ in
        self.yourCarouselView.reloadData()
    }, completion: nil)
}

Use the following delegate method to decide the item width:

func carouselItemWidth(_ carousel: iCarousel) -> CGFloat {
    return yourCarouselView.bounds.width //Whatever the size you want to set
}

And

yourCarouselView.isPagingEnabled = true