Rotate square imageView in ScrollView
I have a gallery of UIImageViews (that are SQUARE) declared as subviews of UIScrollView:
int size = self.view.frame.size.width/number;
int maxSize = [list count]; //amount of images to show in this view
imageViewArray = [[NSMutableArray alloc] init];
for (int i=0,j=1,k=0; i<maxSize; i++, j++){
UIImageView *imageView = [[UIImageView alloc] initWithImage:[list objectAtIndex:i]];
if (i % number == 0)
{
j = 1;
k++;
}
imageView.frame = CGRectMake((size*(j-1)), (size*(k-1)), size, size);
imageView.contentMode = UIViewContentModeScaleAspectFit;
[imageView setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth];
[imageScrollView addSubview:imageView];
imageScrollView.contentSize = CGSizeMake(size*number, size*(maxSize/number));
[imageScrollView setAutoresizesSubviews:YES];
In portrait mode everything is ok. However in landscape i want my images to become bigger both in axe X and Y. With pasted code my images get larger frame only in width, so they are wide and short. I want them to keep their ratio, so still to be square. Any idea..?
BTW: I tried to setAutoresizingMask to flexible height,top and bottom, but it makes my UIImages ev开发者_运维问答en shorter (i dont know why).
You don't want your margins to be flexible, leave them fixed, you only want the internal height/width to be flexible. So try setting only the following two:
[imageView setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
You wrote that the images should increase in size in landscape view, so where are you adjusting the UIImageViews frames? (And if they are getting smaller, then you have a bug in that missing piece of code.)
And @gamozzii is correct, you want the autoresizing on the imageviews to be:
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
精彩评论