> On 24 Jul 2016, at 18:42, Alex Hall <mehg...@icloud.com> wrote:
> 
> I'm making a game based on a board. Every square on the board will be a 
> UIButton so users can tap it. I know the size of the board (2x6) but in 
> similar projects I may not--that is, the board size may be set by a user 
> preference. In either case, I don't look forward to making a bunch of 
> individual IBOutlets, and wonder if there might be a better way. Plus, with 
> an arbitrarily-sized board, I couldn't make and wire up the outlets.
> 
> In such a situation, how would I do this? I'll need each button to respond to 
> a single tap, tap and hold, and double tap. 

I wouldn’t use UIButtons at all for this. I’ll start by assuming you’re talking 
about one tap at a time, ie that you don’t need to be able to tap more than one 
cell simultaneously. You finish one gesture then start another. 

So make your board a UIView, the whole thing, one view, and attach one single, 
one double and one long press gesture recogniser to it, and configure them 
appropriately so they allow each other to run or not, depending on how your 
game works. 

Then all you have to do when you have a gesture which is recognised is to take 
the coordinates of the gesture, and work out which virtual ‘cell’ that 
represents on your board.  This is totally scalable from 1x1 cells to however 
many x however many, the board dimensions are just a property of your custom 
view. You can easily draw your own highlight as the cell is tapped and make it 
look like a button, or probably better look not like a button but like a cell 
in your game being tapped. 

Just make sure your cell to coordinates and coordinates back to cell logic is 
in one place so the drawing and gameplay are using the same transformation as 
the gesture recognisers. 
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (Xcode-users@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/xcode-users/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to