Draw a grid of images using Core Graphics in drawRect:

My problem is this: I have a simple block image from which I want to make a grid. I created an array of CGPoints in my UIView. Then i used

blackImage = [UIImage imageNamed:@"black.png"];

and then

- (void)drawRect:(CGRect)rect {
    for (int j = 0 ; j <= 11; j++)
    {
        for (int i = 0 ; i <= 7; i++) 
        {
            [blackImage drawAtPoint: (CGPointFromString([[self.points objectAtIndex:j] objectAtIndex:i]))];
        }
    }
    [whiteImage drawAtPoint:(CGPointMake((CGFloat)(floor((touchX+0.001)/40)*40), (CGFloat)(floor((touchY+0.001)/40))*40))];

    //  [whiteImage drawAtPoint:(CGPointMake(240.0, 320.0))];   
}

Where TouchX and TouchY are CGPoints where the user touched the screen. Therefore, I basically show another image at the grid point where the user touched.

First of all, the problem is that the whole screen is redrawn every time I call DrawRect. I want to save state (by changing the BOOL array?) And ask the user to drag and drop multiple images onto the screen. However, I cannot use the drawAtPoint method in UImage when I am outside of DrawRect. (gives an error message).

, CoreAnimation Quartz . , UIView ( ) CALayers CGLayers... , , ... , CALayer CGLayer. -, " UIViews " ?

, . , "" .


[self setNeedsDisplayinRect] CGRect . , - DrawRect TouchesMoved, , , iPhone. CALayers? Core Animation , .

+5
3

, UIImage . , drawRect:. , , " ", . .

, setNeedsDisplay: - , . . UIKit () drawRect:.

:

  • , dirty rect drawRect: ( ), , , .
  • touchs, , , , 1.
  • , Quartz - , , - UIImage ( , ).

, 1 2 , . , SO.

+2

, setNeedsDisplayInRect: . , .

CALayer /.

, drawRect: , setNeedsDisplay. drawRect: UIKit , .

+1

77 , CALayers UIViews ( , ), . UIViews CALayers, UIImageViews (, , , UIView backgroundColor ). , , UIImageView .

, , , UIViews, . UIViews CALayers , UIViews .

, CALayers, UIViews .. iPhone, " " " " " iPhone" ".

+1

All Articles