This is what I did. I first set the size of the cell based on the size of the screen (so that we can get the best number of images on each row). You may want to change the numbers to suit your cause.
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
CGFloat widthOfCell =(self.view.frame.size.width-30)/2;
CGFloat heightOfCell =widthOfCell * 1.33;
CGSize returnValue = CGSizeMake(widthOfCell, heightOfCell);
returnValue.height += 5;
returnValue.width += 5;
return returnValue;
}
I then used an image manipulation method to determine the landscape or portrait state, and (for my app) I decided to make every image a portrait:
if (sourceImage.size.width>sourceImage.size.height) {
sourceImage = [[UIImage alloc] initWithCGImage: sourceImage.CGImage
scale: 1.0
orientation: UIImageOrientationRight];
}
If you want to have it the other way round, swap the >
with <
CAVEAT: my rotating method doesn't take into consideration if the picture is pointing left or right. In other words, If an image is landscape by upside down, my code can't recognise that. I hope someone else can help you though, and I hope I haven't gone off track! :)