Home > DeveloperSection > Forums > Scrolling problem using UICollectionView in Xcode?
Andrew Watson
Andrew Watson

Total Post:39

Posted on    January-28-2016 12:07 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 722  View(s)
Rate this:

I have created an image gallery application using UICollectionView in iPhone. My collection view cell are approximately (65, 65) size. For our image gallery I am getting images using ALAssets from the ALAssetLibrary and storing them in a list(NSMutableArray). 

This is my code:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  static NSString *identifier = @"MyCell";
  UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
  UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(0,0, cell.frame.size.width, cell.frame.size.height)];
  UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,50,50)];
  imageView.image = [imageAssetList objectAtIndex:indexpath.row];
  [parentView addSubview:imageView];
  [cell addSubview:parentView];
  return mycell;

Now, my application running perfectly but whenever I will scroll image continuously I have getting scrolling problem, it will not scroll freely.
I google it but I don't get any perfect solution for that.
Please help me, how can I solve this problem.

Tarun Kumar

Total Post:214

Posted on    February-04-2016 10:23 PM

I also faced the same problem in the UICollectionView, so I found the solution to scroll collection view perfectly. You can use this code:
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
for perfect result use above code under this code:
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
I hope it will also solve your problem because this was helpful for me.

Modified On Feb-04-2016 11:06:44 PM

Don't want to miss updates? Please click the below button!

Follow MindStick