Search code examples
iosobjective-ctouchswipegesture

Detecting touchdown, touchup, touchmove events across 4x4 iOS tiles


I am working on a game for iOS that looks a bit like the 'Boggle' board game, basically a 4x4 grid of numbers that you can swipe across with a touch down, touch move and touch up event structure that should return back to the main program the id/content of the 'tiles' swiped as well as 'select' them so that the user has visual feedback that they have been selected (this is my question...how to achieve this). A tile is something that could either be a button or label.

I was able to pull this off on the Windows Phone and PC platform with touch down/up/move events associated with the form itself, the notion of being 'directly over' or pushing 'down', 'moving across' or 'up' a label, and found it simple to hook up the events with the associated down/up/move actions, but can't seem to figure out how to do this on iOS, despite researching gestures as well as the touchup/down/move paradigms and creating several different gesture projects that haven't worked the way I found them to in Windows: http://www.wintellect.com/CS/blogs/jprosise/archive/2011/01/14/building-touch-interfaces-for-windows-phones-part-2.aspx I am guessing labels should be used instead of buttons, but am open to using either. Right now, I have implemented the game with simple button touches, but the game loses a lot of the modern UI feel and natural UI constraints when you can't select a set of adjacent labels with a single swipe. Would really appreciate the help.


Solution

  • Simple!

    /* Lots of code that didn't work, see old version if you want */
    

    No, it wasn't that simple. It seems like UIButton steels the events..

    ..so I made a UIView subclass, with UILabels and custom touch handling (as Clever Error's answer also pointed out), posted on GitHub: https://github.com/LeonardPauli/LPSwipeableInputMatrixView

    Tested and working. But not at all perfect. Should be pretty simple to remake, through.

    Good luck! :)