旋转 iPhone 并保持图像比例

发布于 2024-11-29 00:15:31 字数 557 浏览 5 评论 0原文

我有一个 UIScrollView,其中包含 UIImageViews。所有图像都保持其图像比例 - 我的意思是,例如肖像图像高且窄,而风景图像短而宽。我屏幕上同时有大约 4 个图像(2 个垂直,2 个水平),然后我可以向下滚动。

我的问题是旋转设备。我

[self.imageScrollView setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin];// (etc)

对 imageView 使用相同的方法。但图像不保持其比例。如果我设置: UIViewAutoresizingFlexibleWidth - 图像很宽但高度太小 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth UIViewAutoresizingFlexibleHeight - 图像水平拉伸,而垂直拉伸则变小。

我需要旋转设备(纵向->横向),制作这两个图像(我彼此相邻)以填充间隙并保持这些图像的比例。

I have an UIScrollView, that contains UIImageViews. All images keep their image ratio - I mean that e.g. portrait image is high and narrow, while landscape image is short and wide. I have about 4 images at same time on screen (2 vertically, 2 horizontally), then I can scroll down.

My problem is rotating the device. I use

[self.imageScrollView setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin];// (etc)

And same method for imageView. But images don't keep their proportions. If I set:
UIViewAutoresizingFlexibleWidth - image is wide but heigh is too small
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight - image is stretched horizontally, while vertically it's way to small.

I need to rotate the device (portrait->landscape), make these 2 images (that I have next to each other) to fill gap and keep these images proportions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

我不会写诗 2024-12-06 00:15:31

试试这个功能..

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
        if (orientation == UIDeviceOrientationPortrait) { //Device is portait 
            //Resize the images to fit this orientation
                         image1.frame = CGRectMake(x,x,x,x);
        }
        else {
            //Device is landscape..
        }   
    return YES;
}

Try this function..

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
        if (orientation == UIDeviceOrientationPortrait) { //Device is portait 
            //Resize the images to fit this orientation
                         image1.frame = CGRectMake(x,x,x,x);
        }
        else {
            //Device is landscape..
        }   
    return YES;
}
寂寞清仓 2024-12-06 00:15:31
imageView.contentMode = UIViewContentModeScaleAspectFill;

这解决了我的问题^^

imageView.contentMode = UIViewContentModeScaleAspectFill;

This solved my problem ^^

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