Swift swipe gestures, moving a label, and constraints

Hi there,

I’ve got a lot of elements locked down with constraints–nicely I might add.

One of them is a label.

I’d like to be able to swipe left and right to ‘toggle’ between two labels to display the desired content. I’m unsure where to start looking (aside from a swipe gesture basics) because the label is locked down with constraints.

I’d like the label to appear moving (or at least the contents of each label when it’s their turn to move) and not just be replaced with the other label’s data.

I have some ideas about the “math” behind it, using arrays or counters, to essentially make a toggle: In other words, I don’t mind toggling right or left (for right or left-handed folks). I just want a swipe to swap between 2 sources of content.

Is this something more suited for programmatically doing it? IB doesn’t seem to smell like it’s the route to go.

thanks for the patience.

Hi @thirtywest,

Let me know if you need the methods for swipe gestures and I will post them.

What you can do is set the leading and trailing Constraints, not the label, but the constraints to the label and a IBOutlet. Then programmatically at the constant for the label off the screen, wait for the amount of time you want in the animation, and then move it back onto the screen. Then just change the content for the label.

I would personally create two labels, with the content you want in them. Have one set off screen the other on. And them when the swipe method is called just swap them.

Good luck.

Whoa thank you. I’m almost to the point of getting that going. I’m stuck on a segue. I am just working with two labels, and until I get the data in the proper place I didn’t want to drive ahead with the display.

I’ve been working on setting up longPress gestures programmatically for 4 buttons, and although all 4 of them work, none of the data passes.

I can open the view controller but in the image I’ve attached, I can’t even get this print statement to post to the console to ‘check’ it’s progress. No errors or crashes. It just seems to ignore the prepare.



Couple thoughts: 1. you have the prepare for Segue, where do you initiate the segue? Can you share that code? 2. Have you initialized the receiving var in the MemoryButtonsViewController which will receive the data you want to pass to the new VC?

Sounds like the call to make the segues is not happening. Show us that code. Yes it you use three ``` followed by code and three more ``` following your code.

Let us know and we will see if we can help.

You know I resolved it just now. Since I had made a touchGesture that was activated by a button I kept trying to get the identity of the sender as a UIButton.

When I changed it to: performSegue(withIdentifier: “poppy”, sender: gesture.view)

It began to behave as predicted.

I didn’t see that coming.

Well done! Those eureka moments when we find a problem that has vexed us in the code are particularly satisfying!


absolutely. they clear the way for the mountain of problems waiting in queue!