Note that there are some explanatory texts on larger screens.

plurals
  1. POiCarousel viewForItemAtIndex using custom UIView resuses first images loaded
    primarykey
    data
    text
    <p>I have no trouble using iCarousel with UIImageViews, everything works great.</p> <p>However, I wanted to add some extra drawing with the image, so I did a quick subclass of UIView that included an image and had a custom draw routine. Simple enough. However, inside of the <strong><em>viewForItemAtIndex</em></strong>, when I set the image property, it doesn't update visually. Instead it repeats the n images that represented the visible images and thus the originally loaded objects.</p> <p>Example, I have 26 images, a - z. 5 visible on startup, a - e. Without the 'setNeedsReload' i get images a - e repeatedly, instead of a - z, when I scroll through the view.</p> <p>I have found that if I add '<strong><em>setNeedsDisplay</em></strong>' inside the setImage property, it will work correctly. However, there is a huge performance penalty.</p> <p>My question is two fold:</p> <ol> <li>Am I missing something?</li> <li>Should I just extend UIImageView instead and do the custom drawing inside a 'processImage' style method like Nick did in FXImage?</li> </ol> <p>Thanks,</p> <pre><code>/// GroupImageView.m - (void)setImage:(UIImage *)newImage { image = newImage; [self setNeedsDisplay]; } // override of the drawRect routine. - (void)drawRect:(CGRect)rect { // only draw if we have an image to draw if (image) { CGContextRef context = UIGraphicsGetCurrentContext(); // blah blah, fancy drawing crap CGContextRotateCTM (context, radians((rand() % 5 + 2))); CGContextTranslateCTM(context, -0.5f * insetRect.size.width, -0.5f * insetRect.size.height); CGContextFillRect(context,insetRect); // etc [image drawInRect:insetRect blendMode:kCGBlendModeNormal alpha:[self alpha]]; // etc } } </code></pre> <hr> <pre><code>- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view { if (view == nil) { view = [[GroupImageView alloc] initWithImage:[UIImage imageNamed:@"Loading.png"]]; } CGImageRef ref = [group posterImage]; UIImage* coverImage; if (ref) { coverImage = [UIImage imageWithCGImage:ref scale:1/scaleFactor orientation:UIImageOrientationUp]; } else { coverImage = [UIImage imageNamed:@"Sunflower.png"]; } [(GroupImageView*)view setImage:coverImage]; return view; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload