I recently ran into this problem while developing a game for the iPhone. I used UIButtons to store game plates, then styled them with transparent images, background colors, and text.
Everything worked well for a small number of tiles. However, when we got to 50, productivity dropped significantly. After cleaning Google, I found that others were experiencing the same problem. It seems that the iPhone is struggling with many transparent buttons on the screen right away. I'm not sure if this is a mistake in the UIButton code or just a limitation of the graphic equipment on the device, but in any case it is not under your control as a programmer.
My solution was to draw the board manually using Core Graphics. It seemed complicated at first, but actually it was pretty easy. I just put one big UIImageView on my ViewController in Interface Builder, made it an IBOutlet so that I could change it with Objective-C, and then built the image using Core Graphics.
Since UIImageView does not handle cranes, I used the touchhesBegan method of my UIViewController and then triangulated the x / y coordinates of the touch to the exact tile on my game board.
Now the board is less than one tenth of a second. Bingo!
If you need some sample code, just let me know.
UPDATE: Here is a simplified version of the code I'm using. It should be enough for you to get the gist.
// CoreGraphicsTestViewController.h // CoreGraphicsTest #import <UIKit/UIKit.h> @interface CoreGraphicsTestViewController : UIViewController { UIImageView *testImageView; } @property (retain, nonatomic) IBOutlet UIImageView *testImageView; -(void) drawTile: (CGContextRef) ctx row: (int) rowNum col: (int) colNum isPressed: (BOOL) tilePressed; @end
... and the .m file ...
// CoreGraphicsTestViewController.m // CoreGraphicsTest #import "CoreGraphicsTestViewController.h" #import <QuartzCore/QuartzCore.h>
Axeva source share