2

I have an app which supports both iOS10 and iOS11. In the app I have a uiview pinned to a finger via pan gesture. Pan gesture moves view center only along y axis (x stays the same always). I also have CGAffineTransform tied to the gesture, the more up user moves my view the larger it becomes. "Panned" view contains another view with some content.

Now on iOS11 I have this behavoiur (which I consider correct):

             > - center of content view stays on a vertical line
^  <--[      |      ]-->
|  <----[    |    ]---->
|  <------[  |  ]------>
|  <--------[ ]-------->

But on iOS10 I get this behavoiur:

                > - center of content view moves to the right along with scale growth 
^  <----[      /      ]>
|  <-----[    /    ]--->
|  <------[  /  ]------>
|  <--------[ ]-------->

My code to add content view to panned 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 pan gesture:

... // 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)

As you can see I also cap scale to be between 1 and 1.1.

It seems like either constraints in conjunction with scaling work differently on iOS10 and iOS11 or scaling is "double" propagated to subviews somehow.

Any ideas?

iur
  • 2,056
  • 2
  • 13
  • 30

1 Answers1

3

Don't apply a transform to a view that is positioned by constraints. The results are undefined (which is exactly what you are experiencing: it "means" one thing on one system and another thing another).

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • PannedView is NOT positioned by constraints, contentView inside of it IS positioned by constraints. Does it mean that if I want to apply transform to some view any of its subviews in the whole tree down can't be positioned by constraints? – iur Jan 19 '18 at 16:15
  • See for yourself. Remove the constraints from the content view and see what happens. – matt Jan 19 '18 at 16:20
  • Did it already :). Thanks. You are right. If I layout contentView manually in layoutSubviews and set `translatesAutoresizingMaskIntoConstraints` to `true` it behaves "correctly". ContentView contents are still using constraints and it seems to work. Do you happen to know the answer to the second part of my question in comment: can I keep constraints for contentView subviews tree? – iur Jan 19 '18 at 16:24