旋转方imageview的滚动型
问题描述:
我的UIImageViews(是SQUARE)的画廊声明的UIScrollView的子视图:旋转方imageview的滚动型
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轴上变得更大。粘贴代码时,我的图像仅在宽度方向上变大,因此它们宽而短。我希望他们保持他们的比例,所以仍然是方形的。任何想法..?
顺便说一句:我试图setAutoresizingMask灵活的高度,顶部和底部,但它使我的UIImages更短(我不知道为什么)。
答
你写的图像应在横向视图大小增加,所以你在哪里调整UIImageViews的框架? (如果他们变得越来越小,那么你必须在失踪一段代码中的错误。)
而且@gamozzii是正确的,你想在imageviews的自动尺寸是:
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
答
你不希望你的利润率是灵活的,让他们固定,你只想要内部的高度/宽度是灵活的。因此,尝试只设置有以下两种:
[imageView setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
+0
在这种情况下,当我旋转到风景,所有图像变得越来越小,直到他们完全消失... – Vive
问题是,你从哪里得到sizeX?数量是多少? – Seega
@Seega对不起,sizeX ==大小,我改变它时复制粘贴到堆栈溢出,没有注意到一个离开。已在我的帖子中更正。数字是图库中的列数。 – Vive