【问题标题】:Image resizing in Scrollview在 Scrollview 中调整图像大小
【发布时间】:2012-07-24 08:35:11
【问题描述】:

我在ScrollView 中有一个ImageView,并在某个时候调整了ScrollView 的大小。问题是,ImageView 正在调整为与ScrollView 相同的大小,但我希望它保持原始图像大小。

我正在做的是这样的:

scrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); // fullscreen scrollview
[scrollView setContentMode:UIViewContentModeTopLeft]; //i want the content to be on the top left, thats correct right?
[scrollView setContentSize:CGSizeMake(imageInScrollView.frame.size.width, imageInScrollView.frame.size.height)]; // now im setting the size of the content, which is like 200x200 but it shows in fullscreen

请阅读我的代码旁边的 cmets,谢谢!

【问题讨论】:

    标签: ios xcode imageview scrollview


    【解决方案1】:

    您需要将autoresizingMask 更改为UIView

    autoresizingMask
    一个整数位掩码,用于确定接收器如何调整自身大小 当其父视图的边界发生变化时。

    你可以这样做:

    [myImageView setAutoresizingMask:UIViewAutoresizingNone];
    

    【讨论】:

      【解决方案2】:

      UIScrollViewcontentSize 不影响绘图,仅用于滚动目的(即定义用户可以在其中滚动的矩形)。

      请提供有关imageInScrollView 和它所包含的UIImageView 的更多信息。特别是检查它的frame 属性是否正确,并检查它的autoresizingMask:你可能想要类似的东西

      imageView.autoresizingMask = UIViewAutoresizingNone;
      

      最后,你应该这样做:

       [scrollView setContentSize:imageView.frame.size];
      

      因为这样更简单

      【讨论】:

      • 嗨,我检查了两者的框架。 imageInScrollView(实际上是一个 ImageView)和滚动视图 350.000000, 335.000000 // imageview -- 540.000000, 576.000000 // scrollview.. 它没有用 autoresizingnone
      • imageView.image.size 是什么?
      • 对不起,image.size 是 350x335 而 imageView 的 frame 是:540.000000, 516.857178
      • imageView.contentMode = UIViewContentModeCenter ?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      • 2010-11-20
      • 1970-01-01
      • 2015-01-09
      • 2013-01-16
      相关资源
      最近更新 更多