Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

HarryWorksInc

macrumors regular
Original poster
Feb 21, 2010
179
0
I am just creating a simple drawing program, I have been a developer for years now and I know I must be doing something insanely stupid but heres my code,
HTML:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	CGPoint thumbPoint;
	UITouch *thumb = [[event allTouches] anyObject];
	thumbPoint = [thumb locationInView:thumb.view];
	
	UIImageView *newImage = [[UIImageView alloc] initWithFrame:CGRectMake(thumbPoint.x, thumbPoint.y, 17, 17)];
	newImage.image = [UIImage imageNamed:@"BlackDot.png"];
}

I don't know what i'm doing wrong but all this is supposed to do is create a small square on the screen this repeats in the touchesMoved void.

Nothing happens though, help would be much obliged.
 
1) That is a totally insane way to draw a single pixel.

2) You've not added the new view a subview of any visible view so it's not actually on screen anywhere.
 
The reason your way is insane is that you'll end up with so many views that performance will be poor. And there will probably be quite a lot of lag too.

Option 1:

Composite yourself: just create a UIImage and composite your "pixel" image yourself. Downside of this is tracking your pixels and the more you have the longer this will take

Option 2:

Well then re-lock focus on the composited image from last time and composite the new pixel in. This will probably work OK

Option 3:

Do it the "right" way. Create a CGBitmapContext with the correct options and "draw" by simply manipulating the image bytes directly.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.