Right now i have a few buttons next to each other like this:
User has to press all of them to select the whole row (i have a few rows). It would be natural to enable them to swipe over them to select them all. I also need to get information about how many buttons were selected.
Could you please help me how to achieve this? Do i have to create my own view or implement some gesture listeners?
Depending on what you exactly trying to achieve there are 2 easy ways :
- Simplest : add a
UISwipeGestureRecognizerto your view (or to a view with only the 4 buttons on it) and implement delegate interface within your view controller. When a swipe (in the good direction) is done, you receive an event and you perform your "unlock".
UIGestureRecognizer (doc here) :
Clients of gesture recognizers can also ask for the location of a gesture by calling locationInView: or locationOfTouch:inView:.
So with that + implementing
UIGestureRecognizerDelegate (doc here) you should be able to check exactly what you want.
- If you want to manually track the user finger you can just extend UIView and implement :
You can here have the full control (
CGRectContainsPoint() will be useful).
Edit : Something important you have to keep in mind to make your choice is speed. If the user can select the row even with a slow and non-linear gesture (put the finger on the first button then > slowly go to second > go to third > back to second > go to last for instance), you should extends UIView and on the touch began make the first image highlight and then follow the finger until the touchEnd on the last button. It should be more user friendly (depending on what you are trying to achieve of course).