What to replace UIButton to increase the frame rate?

I created a minesweeper clone game, and I made a 30 x 30 grid. Now, in my initialization project, I planned to use UIButton for each cell to use its touchDown and touchUpInside. But my problem is the use of UIButton makes the game slow in scaling and especially when loading or adding each cell (900 pcs.) To UIView.

Now I plan to use images instead of UIButton, and I heard about CALayer for easy animation. Can you suggest how I can use this CALayer for my implementation or replacement of UIButton?

Thanks.

0
source share
2 answers

I would advise taking the Core Animation path for this. You can use the NSView subclass to receive and handle touch events, after which you can then use the touch location to calculate the cell that was deleted and update your model accordingly.

You organize CALayers in a hierarchy, so the complexity of the view tree will depend on the other user interface elements you want to have — you will have a CALayer containing 900 sublayers.

Using Core Animation will also let you enjoy the animation.

It will be a bit more complicated, but you just need to bite the bullet and get stuck in the Core Animation documentation and / or buy a book.

Good luck.

Edit: Ivan suggests using the hitTest message. This way you can get the layers to tell you which one was hit. Using this is obviously pretty good. However, if you are looking for speed, it might be quicker to avoid this and just fix the problem. This makes assumptions about how your game works (i.e. the buttons / cells do not move the location). If you get a chance to try both and let us know how it works .: O)

+3
source

On the Cocoa desktop there is NSCell, which is an easy alternative to NSButton, but it is an older technology before CALayer and Core Animation (they do not conflict with each other)

To create a custom button, create your own class or extend it for CALayer delegates. Then, to find out which button is pressed, use the [hitTest] method, which will return an effective click.

+1
source

All Articles