Button Swipe

I want to add to my app a swipe button. I want to be able to swipe between a certain amount of buttons. Then the button that is selected is the one in the center. I want it to look so that only one button is on the screen at a time, and the others rotate of to the side yet you can still see a little bit of them. I don't have any code present at the moment. I am building the app using Swift.

Accepted Reply

OK.


Personnaly, I would use qegmented control for that.


But I understand you want something a bit more funny to use ?


Have you difficulties with the following :

- create an image with the drawing of all buttons, side by side

- create a view that has the width of a little less that 2 buttons

- position the image in the view so that the selected "button" sits in the middle

- swipe would just change the selected button and force redraw

- then detect the click is in the central button

Replies

What does "swipe" mean in this context? Normally it means a gesture where the finger touches the display then moves rapidly in some direction, then lifted off the display, without any particular precision about where it's lifted. That doesn't seem to fit your scenario where it matters very much where it's lifted — at least I think that's what you mean.


Or, imagine something like a table view whose cells are … let's say "options" rather than "buttons". You could push or pull left or right, to get a certain option into the center, then do some action when your finger lifted, based on what was in the center. I wouldn't necessarily call that a swipe (more of a pan gesture) but it might be something like what you had in mind.


Or is this more like gambling, where you flick the display, and see where it happens to stop, without really knowing in advance?

I understand you want an effect like in Finder selection when you flip the thumbnails ?


If I had to do it, I would :

- create an image with the drawing of all buttons, side by side

- create a view that has the width of a little less that 2 buttons

- position the image in the view so that the selected "button" sits in the middle

- swipe would just change the selected button and force redraw

- then detect the click is in the central button


However, the visual effect may not be very good if you don't shrink the images on the border.


How many buttons will you have ?

If more than 5, I may understand what you try ; otherwise, segmented control may be better.

I want to add 5 buttons that you can swipe between. What I mean by swipe is you swipe to the left and right not up and down.

OK.


Personnaly, I would use qegmented control for that.


But I understand you want something a bit more funny to use ?


Have you difficulties with the following :

- create an image with the drawing of all buttons, side by side

- create a view that has the width of a little less that 2 buttons

- position the image in the view so that the selected "button" sits in the middle

- swipe would just change the selected button and force redraw

- then detect the click is in the central button

Do you mind explaining the steps in more detail.

- create an image with the drawing of all buttons, side by side

You should create images for your buttons (maybe just text)

Then, assemble the images in a single image for convenience


- create a view that has the width of a little less that 2 buttons wide


- position the image in the view so that the selected "button" sits in the middle

When you first load the view, set the bounds so that the selected button image is in the middle ; you would have partial view of 2 other buttons, on left and right


- add a swipe gesture to the view (can be done in Interface Builder)


- control drag from Connection inspector for the view to the code to create IBAction


- swipe would just change the selected button and force redraw

That's the IBAction for the swipe

You change the bounds to redraw in new position


- then detect the click is in the central button

Add a tap gesture in the view and test where you tap to check it is in the central image


Note: selection could also be done directly at the end of swipe



So that's a sketch ; but it will be some effort to make it smooth and fun to use! Good luck.

Could you explain this in more detail and show examples I don’t understand what you mean.

Showing examples on the forum is just impossible, unfortunately.


Could you tell in my detailed text what you don't understand ? I'll try to explain more.