在ScrollView中旋转方形imageView
我有一个 UIImageViews 画廊(正方形)声明为 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 轴上都变得更大。通过粘贴代码,我的图像仅在宽度上获得更大的框架,因此它们又宽又短。我希望它们保持比例,所以仍然是正方形。有什么想法吗..?
顺便说一句:我尝试将 AutoresizingMask 设置为灵活的高度、顶部和底部,但这使我的 UIImages 更短(我不知道为什么)。
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 even shorter (i dont know why).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不希望边距灵活,将其保持固定,您只希望内部高度/宽度灵活。因此,请尝试仅设置以下两项:
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:
您写道图像应该在横向视图中增加尺寸,那么您在哪里调整 UIImageViews 框架? (如果它们变得越来越小,那么您在缺失的代码段中就有了错误。)
@gamozzii 是正确的,您希望图像视图的自动调整大小为:
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: