我有一个UIImageViews(即SQUARE)库,被声明为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];
在纵向模式下一切正常。然而在风景中,我希望我的图像在X轴和Y轴上变得更大。使用粘贴的代码,我的图像仅在宽度上获得更大的帧,因此它们宽而短。我希望他们保持比例,所以仍然是正方形。有什么想法..?
BTW:我试图将setAutoresizingMask设置为灵活的高度,顶部和底部,但它使我的UIImages更短(我不知道为什么)。答案 0 :(得分:2)
您不希望边距灵活,保持固定,只希望内部高度/宽度灵活。因此,请尝试仅设置以下两个:
[imageView setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
答案 1 :(得分:0)
您写道,在横向视图中图像的大小应该会增加,那么您在哪里调整UIImageViews框架? (如果它们变得越来越小,那么你在那段缺失的代码中就会有一个错误。)
并且@gamozzii是正确的,您希望对图像视图进行自动调整:
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;