Move the label position to swift with a gesture

advertisements

I have a label in my view controller. I am trying to move the position of the label 50 points to the left every time I tap the label. This is what I have so far but my label won't move in the simulation. I do have constraints on the label. It is about 100 wide and 50 in height, and it is also centered in the view controller.

    override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    let tapGesture = UITapGestureRecognizer(target: gestureLabel, action: #selector(moveLabel))
    gestureLabel.addGestureRecognizer(tapGesture)

}

func moveLabel(){
    if(left){
        moveLeft()
    }
    else{
        moveRight()
    }

}

func moveLeft(){
    let originalX = gestureLabel.frame.origin.x
    if(originalX < 0){
        bringIntoFrame()
    }
    else{
        gestureLabel.frame.offsetBy(dx: -50, dy: 0)
    }
}


UILabel's userInteractionEnabled is false by default. Try setting it to true