简体   繁体   English

在我的情况下,如何正确获取scrollView的contentSize,zoomScale和contentOffset?

[英]How to get the contentSize, zoomScale and contentOffset of scrollView properly in my case?

I having the following scenario: 我有以下情况:

  • A scrollView which contains an imageView. 一个包含imageView的scrollView。
  • This imageView is zoomable from 1.0 to 5.0 scale value. 此imageView可以从1.0缩放到5.0缩放值。
  • Whenever the orientation changes, I resize the imageView to a specific aspect ratio and then set the contentSize of scrollView to the size of the contained imageView. 每当方向改变时,我都会将imageView调整为特定的宽高比,然后将scrollView的contentSize设置为所包含imageView的大小。

  • When the scrollView is not zoomed, the imageView resizes appropriately as per my resize code during any orientation. 当scrollView不缩放时,imageView在任何方向上都按照我的调整大小代码适当调整大小。

  • When my scrollView is zoomed in the initial orientation (the orientation during which it was generated), panning the scrollView to the edges goes well. 当我的scrollView缩放到初始方向(生成它的方向)时,将scrollView平移到边缘会很好。
  • (Issue:) In the zoomed state, if the orientation of device changes, the imageView frames are recalculated by my resize code and zoomScale is set to 1. However, if I zoom again in the new orientation, I find that the imageView gets a some 100 to 200 pixels of offset. (问题:)在缩放状态下,如果设备的方向发生变化,则我的尺寸调整代码将重新计算imageView帧,并将zoomScale设置为1。但是,如果我再次以新方向进行缩放,则会发现imageView得到一个大约100到200像素的偏移量 This causes the imageView to hide some contents on one edge ( i cannot pan more to view the edge ) and it scrolls extra leaving a gap on the other edge which contains nothing. 这将导致imageView在一个边缘上隐藏一些内容(我无法平移以查看该边缘),并且它会额外滚动,从而在另一边缘上留有空隙,其中不包含任何内容。

How can I get this corrected ? 我该如何纠正? I want the scrollView's contentSize to be such that be its internal imageView in zoomed state or not, after any orientation, the zoomed imageView should be able to pan in all directions till its edge meet the edge of its parent scrollView. 我希望scrollView的contentSize使其是否处于缩放状态的内部imageView,在任何方向之后,缩放的imageView都应该能够在所有方向上平移,直到其边缘与其父scrollView的边缘相交。

You should not resize image view. 您不应该调整图像视图的大小。 Use [imageView sizeToFit] . 使用[imageView sizeToFit]。 You should recalculate zoom of scroll view for fit ImageView. 您应该重新计算滚动视图的缩放以适合ImageView。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM