Carousel3D cannot handle 400 + items - pls help!


#1

I am using the 3D carousel and I am using it as a slide presenter. I have added 403 items and when I try to swipte to move to the next item the carousel drags and juimps very slowly to the next item. It works fine on the simulator, but on the any device, iPhone 4s or iPad it acts like there is not enough processing power. Is this expected behavior? Is there a limit to how many items can be added to your carousel control before it starts to work sluggishly?


#2

It’s probably a bit more complicated than “the carousel can’t handle it” — what are you presenting? How are you preparing and displaying the contents of the individual carousel items? Is this done on the main thread, or a background thread?

Have you used Instruments to profile the behaviour and see what’s taking all the CPU time while you’re dragging the carousel?

I’d try to answer those questions first — you’ll probably find it’s the way in which you prepare/display the individual carousel items.


#3

Well I am using the example code CarouselGettingStarted with a simple modification and passing the text from a NSArray here is the code

  • (UIView *)createObjectForIndex:(NSUInteger)index andSize:(CGSize)size 

I added a NSString to this method and I have a NSMutableArray populated with 403 strings of text that I pass using a for loop to createObjectForIndex:

    for (int i=0; i<[textArray count]; i++) {

        UIView *item = [selfcreateCarouselItemForIndex:i];

        item.tag = i;

        

        [items addObject:item];

    }

  • (UIView *)createCarouselItemForIndex:(int)index

{

    UIView *item = [CDItemFactory createObjectForIndex:index andSize:CGSizeMake(200.0, 200.0) andText:[_textArray ObjectAtIndex:index]];   

    item.layer.shouldRasterize = YES;

    UIView *viewToReflect = item;

    item = [[SEssentialsDecoratedReflectedViewalloc] initWithView:viewToReflect];

    return item;

}

@implementation CDItemFactory

  • (UIView *)createObjectForIndex:(NSUInteger)index andSize:(CGSize)size andText:(NSString *)text

{

    UIView *item = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];

    item.userInteractionEnabled = YES;

    UIColor *oddColor = [UIColor colorWithRed:140/255.f green:16/255.f blue:92/255.f alpha:1.f];

    UIColor *evenColor = [UIColor colorWithRed:214/255.f green:105/255.f blue:36/255.f alpha:1.f];

    item.backgroundColor = index % 2 ? evenColor : oddColor;

    item.layer.borderWidth = 2.f;

    item.layer.borderColor = [item.backgroundColorcolorWithAlphaComponent:0.3].CGColor;

    item.layer.cornerRadius = 10.f;

    item.clipsToBounds = YES;

    UILabel * textLbl = [[UILabel alloc] initWithFrame:CGRectMake(13, 70, size.width-25, size.height-280)];

    textLbl.backgroundColor = [UIColorclearColor];

    textLbl.text = text;

    textLbl.font = [UIFont boldSystemFontOfSize:20];

    textLbl.numberOfLines = 0;

    [textLbl sizeToFit];

    [item addSubview:textLbl];       

    return item;

}

@end


#4

http://screencast.com/t/BL5j28Zl 

instruments screenshot - looks like the carousel is using a LOT of memory - any thoughts on what I can do ?


#5

You’re coming at this the wrong way.

Implement an SEssentialsCarouselDataSource and it will only create a few of the required views, and only as they’re needed. Views will be recycled, drastically reducing memory and improving performance.


#6

I am using the delegate, however I found my glitch. I had carousel3D.maxNumberOfItemsToDisplay = 403 – when you said that the views will recycle i figured i could set this to 5 and it worked perfectly, no sluggishness.

So the lesson here is dont set this to the entire amount of items in your carousel. Thanks for you help!