Reputation: 21
I would like to draw a image on the screen where ever the user touches.
I can't figure out how to do it.
Please help
thank you!
Upvotes: 2
Views: 3076
Reputation: 1401
Tada!!!
With Images:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event {
UITouch *touch = [touches anyObject];
touchPoint = [touch locationInView:self.view];
CGRect myImageRect = CGRectMake(touchPoint.x, touchPoint.y, 20.0f, 20.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"YourImage.png"]];
myImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];
}
This code will draw an image wherever you touch!!
I couldn't test it on a device yet, but i believe it would lag just a tiny bit. (because of many images on screen)
With Quartz:
The second way is to use Quartz, try this link:http://www.ipodtouchfans.com/forums/showthread.php?t=132024
Upvotes: 3
Reputation: 620
You'll have to be creative on that one, you would have to catch the users touch points and (As the user is touch and moving about the screen) draw a point, line, circle, or image on the main object/view you are using. If you want to save the screen as an image you can use grab a snapshot of the application or view and store it locally.
Apple's got a simple application that does this, http://developer.apple.com/iphone/library/samplecode/GLPaint/Introduction/Intro.html. Once you download it, you can see how it catches the touch points and paints the lines. Just modify what it paints.
Hope I helped, Apple Development is such a Grey area to me.
Upvotes: 3