如何在UIScrollView中缩放视图,锚点位于中心? [英] How to zoom a view in UIScrollView with anchor point in center?

查看:157
本文介绍了如何在UIScrollView中缩放视图,锚点位于中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIScrollView中有一个用户可以放大的视图。

I have a view in UIScrollView in which the user can zoom into.

视图与UIScrollView框架的大小相同。但是,该视图的子视图更大,更集中。它是一个与UIScrollView具有相同大小的容器,具有居中内容。

The view has the same size as the UIScrollView frame. However, the subviews of that view are bigger and centered. It's a container with same size as UIScrollView with centered content.

当缩小时,UIScrollView使用一个笨拙的锚点改变内容的比例到左上角,而不是一个居中的。

When zooming out, UIScrollView changes the scale of the content with an awkward anchor point to the upper left, rather than a centered one.

有没有办法改变这种行为,以便放大或缩小相对于中心而不是左上角的缩放?

Is there a way to change this behavior such that when zooming in or out the zoom happens relative to the center rather than the upper left corner?

推荐答案

是的我相信你可以更改视图层的 anchorPoint 。像这样 -

Yes I believe you can change the anchorPoint for a view's layer. like so -

[self.yourView.layer setAnchorPoint:CGPointMake(0.5, 0)];

此图中适当定义了锚点的坐标 -

The coordinates of the anchor point are aptly defined in this diagram -

如果您希望动画从左中心锚定,则将anchorPoint设置为(0.0,0.5),即图中的B点。

If you want the animation to anchor from left-center then set the anchorPoint to (0.0, 0.5) i.e. point B in the figure.

这篇关于如何在UIScrollView中缩放视图,锚点位于中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆