使用UIScrollView,缩小时如何使内容视图保持在中心?
最小比例为 0.5 最大
比例为 2.0
我需要始终使用较大的 contentSize
来让 UIScrollView
能够拖动内容。因此,随着内容的 CGRect 变化,UIScrollView
的 contentSize
也在变化。
但是,当我缩小时,如果比例低于 1.0,contentOffset
会突然更改为 {0.0, 0.0},这使得在保持内容相对于叠加视图的位置的同时调整内容大小变得非常困难(例如衣服图像)。
换句话说,我无法在保持内容视图位于 UIScrollView 中心的同时缩小内容视图。
请帮助我找到使用 UIScrollView
进行放大/缩小的正确方法,同时保持内容视图的位置。
The minimum scale is 0.5
The maximum scale is 2.0
I need to always use larger contentSize
for UIScrollView
to be able to drag around the content. So, as the CGRect
of the content is changing, contentSize
of UIScrollView
is also changing.
However, as I zoom out, if the scale is going below 1.0, contentOffset
is abruptly changed to {0.0, 0.0}, making it very difficult to resize the content while keep it's position to the overlay view (e.g. a clothe image).
In other words, I can't make the content view smaller while keeping it positioned at the center of the UIScrollView
.
Please help me to find the right way to use zoom in/out with UIScrollView
while keeping the position of the content view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该解决方案基本上是在初始设置时使用
contentInset
来将内容保持在中心,而不是contentOffset
。在不修改contentInset
的情况下,放大或缩小的对象可以始终位于中心。The solutions is basically about using
contentInset
at initial setup to keep the content at the center, instead ofcontentOffset
. WithcontentInset
being unmodified, zoomed in or out object can be at the center all the time.这个问题在帖子中已经得到了很好的回答:
UIScrollView 与居中 UIImageView,如照片应用
特别是,请参阅 JosephH 的答案本身是从 2010 年 WWDC 演示中挑选出来的。
Matt Neuburg 的书中也使用相同的 WWDC 参考文献对此进行了介绍:
http://www.amazon.com/Programming-iOS-6-Matt-Neuburg/dp/1449365760/ref=sr_1_1?ie=UTF8&qid=1367363707&sr=8-1&keywords=programming+ios6
其来源可以在这里找到(参见第 20 章):
https://github.com/mattneub/Programming-iOS-Book-Examples
对我来说,悬而未决的问题是,这是否可以作为约束的一部分来完成。
This has been answered pretty well in the post:
UIScrollView with centered UIImageView, like Photos app
In particular, refer to JosephH's answer which itself is culled from the 2010 WWDC presentation.
This is also covered in Matt Neuburg's book, using the same WWDC reference:
http://www.amazon.com/Programming-iOS-6-Matt-Neuburg/dp/1449365760/ref=sr_1_1?ie=UTF8&qid=1367363707&sr=8-1&keywords=programming+ios6
The source of which is available here (see chapter 20):
https://github.com/mattneub/Programming-iOS-Book-Examples
The open question for me, is can this not be done as part of the constraints.