在ScrollView中旋转方形imageView

发布于 2024-12-01 07:27:03 字数 1064 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失退 2024-12-08 07:27:03

您不希望边距灵活,将其保持固定,您只希望内部高度/宽度灵活。因此,请尝试仅设置以下两项:

[imageView setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];

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];
青巷忧颜 2024-12-08 07:27:03

您写道图像应该在横向视图中增加尺寸,那么您在哪里调整 UIImageViews 框架? (如果它们变得越来越小,那么您在缺失的代码段中就有了错误。)

@gamozzii 是正确的,您希望图像视图的自动调整大小为:

imageView.autoresizingMask = 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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文