我有一个同时支持 iOS10 和 iOS11 的应用程序。在应用程序中,我通过平移手势将 uiview 固定到手指上。平移手势仅沿 y
轴移动 View 中心(x
始终保持不变)。我还将 CGAffineTransform 与手势绑定(bind)在一起,用户向上移动我的 View 越多,它就变得越大。 “平移” View 包含另一个包含一些内容的 View 。
现在在 iOS11 上我有这种行为(我认为这是正确的):
> - center of content view stays on a vertical line
^ <--[ | ]-->
| <----[ | ]---->
| <------[ | ]------>
| <--------[ ]-------->
但是在 iOS10 上我得到了这个行为:
> - center of content view moves to the right along with scale growth
^ <----[ / ]>
| <-----[ / ]--->
| <------[ / ]------>
| <--------[ ]-------->
我将内容 View 添加到平移 View 的代码:
// self is PannedView
self.addSubview(contentView)
contentView.translatesAutoresizingMaskIntoConstraints = false
// add constraints:
// self.width = contentView.width
// self.height = contentView.height
// self.centerX = contentView.centerX
// self.centerY = contentView.centerY
处理平移手势:
... // handle some unrelated stuff
panView.center.y = self.panStartPoint.y + panDeltaY // where panDeltaY is basically a translation of a UIPanGestureRecognizer
... // some scale calculation logic, calc scale addition depending on pan touch location
let scale = 1 + movePercent * 0.1 // where movePercent is between 0 and 1
panView.transform = CGAffineTransform.identity.scaledBy(x: scale, y: scale)
如您所见,我还将比例限制在 1
和 1.1
之间。
似乎与缩放相结合的约束在 iOS10 和 iOS11 上的工作方式有所不同,或者缩放以某种方式“双重”传播到 subview 。
有什么想法吗?
最佳答案
不要对受约束定位的 View 应用变换。结果是未定义的(这正是您所经历的:它“意味着”一个系统上的一件事,而另一个系统上的另一件事)。
关于ios - CGAffineTransform 比例在 iOS10 上移动 View 中心(但在 iOS11 上则不然),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48345088/