user2636197 user2636197 - 1 month ago 21
iOS Question

Swift change cgpoint .center value

I am using a CGPoint value to set where a animation starts.

transition.startingPoint = startButton.center


If I do
print(startButton.center)
the output will be:
(292.0, 22.0)


What I now want to do is to edit that values Y position so the animation starts a bit lower on the screen and I can pass the new value to the
transition.startingPoint = newVal

Answer

Here is what you need:

var startingPoint = startButton.center
startingPoint.y += 20
transition.startingPoint = startingPoint

Or:

let buttonCenter = startButton.center
transition.startingPoint = CGPoint(x: buttonCenter.x, y: buttonCenter.y + 20)
Comments