0

I have a scroll view with many UIViews, and these views have UIImageViews-that i load images into, while scrolling.

So every page has 4 of these views,that are preloaded to scroller at start, and i load the next page images while scrolling. I do that in another thread , and still, scroller not entirely scrolls fast, if you look good it has some tiny flicks .

here is the function that loads them :

-(void)loadMainImageToIndex:(int)index
{
    NSDictionary *dic=[mainData objectAtIndex:index];
    NSString *userImageUrl=[dic objectForKey:@"url"];
    NSURL *userUrl=[NSURL URLWithString:userImageUrl];


    [self downloadImageWithURL:userUrl completionBlock:^(BOOL succeeded, NSData *tdata)
     {
         if (succeeded)
         {
             //load back
             dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^
                            {
                                UIImage *image=[UIImage imageWithData:tdata scale:0.25];
                                if (image)
                                {
                                    UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
                                    [image drawAtPoint:CGPointZero];
                                    image = UIGraphicsGetImageFromCurrentImageContext();
                                    UIGraphicsEndImageContext();
                                }
                                dispatch_async(dispatch_get_main_queue(), ^
                                               {

                                                   UIImageView *view=[mainImagesArray objectAtIndex:index];

                            });

         }
     }];

The url is loaded Asynch.

Curnelious
  • 1
  • 16
  • 76
  • 150
  • what mainImagesArray contain , its a image collection or imageview collection ? – Pawan Rai May 17 '14 at 20:23
  • Do you want to consider UICollectionView instead of UIScrollView alone. It would be more easier to implement such things and on the top of it, you could create the layout any how you would want. – Sandeep May 17 '14 at 20:43
  • @insane-36 actually UICollectionView is such a problematic thing. if you REALLY wants a good UI, the reusable cells thing is awful. i have investigated the issue for week, and found a few serious bugs that Apple is not going to fix soon, which not allows you to set a dynamic cell height and more. i ended up making my own collection view in just 3 hours with a great performance. if you will dig into this, and not just make a simple collection, you will find many frustrated developers:my last answer: http://stackoverflow.com/questions/23699016/a-uicollectionview-bug-with-a-dynamic-height – Curnelious May 18 '14 at 09:48

1 Answers1

0

Turned out that the views shadow cause this thing :

   //self.layer.shadowOffset=CGSizeMake(6.0, 6.0);
        //self.layer.shadowColor=[UIColor blackColor].CGColor;
        //self.layer.shadowRadius = 3;
        //self.layer.shadowOpacity = 0.7;

Removing this solves the problem.

self.layer.shouldRasterize = YES;  //solve the problem,
Curnelious
  • 1
  • 16
  • 76
  • 150