I have an if statement checking the velocity of the object I'm moving (an image). The point of the statement is to determain which way the image is being influenced, and once it does so, it locks either the X or Y plane, so that it's a smooth left and right movement, or smooth up and down movement.
As the code is below (checking first for right movement, then left, so on) the movement is much smoother if you're going left or right. However, sometimes, when trying to influence the movement up or down, it sort of gets locked into the left and right movement. This I believe is because it's looking first in the if statement for left and right movement. If I move the up and down to be checked first, the left and right movement gets choppy instead. Is there a better way to do this?
let velocity = recognizer.velocity(in: self.view) if velocity.x > 75 { movingRight = true myBlocks[objectDragging].center.y = CGFloat(initPosy) } else if velocity.x < -75 { movingLeft = true myBlocks[objectDragging].center.y = CGFloat(initPosy) } else if velocity.y < -30 { movingUp = true myBlocks[objectDragging].center.x = CGFloat(initPosx) } else { movingDown = true myBlocks[objectDragging].center.x = CGFloat(initPosx) }