【问题标题】:Is there a built in way to make my UIImageView fit the entire contents of a UIImage? Am I just missing something?有没有一种内置方法可以让我的 UIImageView 适合 UIImage 的全部内容?我只是错过了什么吗?
【发布时间】:2011-08-06 00:24:30
【问题描述】:

我有一个模态视图,我用UIModalPresentationPageSheet 样式呈现,这个视图有一个滚动视图,并且该滚动视图内部有一个 mageView,以便我可以显示图像,并允许用户操作,例如缩放,等等

在 viewDidLoad 中,这是我设置所有内容的方式:

CGRect imgFrame = CGRectMake(0, 0, img.size.width, img.size.height);
imageView.frame = imgFrame;
[imageView setImage:img];

效果很好,但我遇到的问题是,如果我的图像在横向模式下大于有点小的 modalView 尺寸(由于 UIModalPresentationPageSheet 样式),它不会缩小和缩放所以我可以看到整个画面,它只显示了图像的 2/3,为了看到更多内容,我必须实际缩小。

我已将 contentMode 设置为UIViewContentModeScaleAspectFit,但它仍然没有改变任何东西。

我错过了什么吗?

【问题讨论】:

    标签: iphone uiimageview uiimage zooming aspect-ratio


    【解决方案1】:

    根据当前方向,将图像视图的框架设置为具有屏幕尺寸的最大宽度和高度。

    类似:

    CGRect imgFrame = CGRectMake(0, 0, min(320 ,img.size.width), min(480, img.size.height);
    

    这适用于 iPhone 上的纵向模式(iPad 不同)。当方向发生变化时,您必须重置该框架。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-18
      • 1970-01-01
      • 2016-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多