【发布时间】:2018-01-20 00:11:52
【问题描述】:
我有一个同时支持 iOS10 和 iOS11 的应用程序。在应用程序中,我通过平移手势将 uiview 固定在手指上。平移手势仅沿y 轴移动视图中心(x 始终保持不变)。我也将 CGAffineTransform 绑定到手势,用户移动我的视图越多,它就越大。 “平移”视图包含另一个包含一些内容的视图。
现在在 iOS11 上我有这种行为(我认为这是正确的):
> - center of content view stays on a vertical line
^ <--[ | ]-->
| <----[ | ]---->
| <------[ | ]------>
| <--------[ ]-------->
但在 iOS10 上我得到了这种行为:
> - center of content view moves to the right along with scale growth
^ <----[ / ]>
| <-----[ / ]--->
| <------[ / ]------>
| <--------[ ]-------->
我将内容视图添加到平移视图的代码:
// 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 上,与缩放相关的约束的工作方式不同,或者缩放以某种方式“双重”传播到子视图。
有什么想法吗?
【问题讨论】:
标签: ios swift ios-autolayout cgaffinetransform