Hi all,
I'm fairly new to the iPhone SDK. I'm working out a little test project which adds a small black dot every time you click the screen. First of all, is there a way I can add a dot
without having to make a UIImageView?
I looked around the Internet, but I couldn't find anything. So the error-free code I came up with was this, in "FirstViewController.h":
Code:
@implementation FirstViewController
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Touches began!");
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
UIImage *blackDot = [UIImage imageNamed:@"Black Dot.png"];
UIImageView *dotView = [[[UIImageView alloc] initWithImage:blackDot] initWithFrame:CGRectMake(touchPoint.x, touchPoint.y, 2.0, 2.0)];
NSLog(@"Touch point frame: x: %g y: %g w: 2.0 h: 2.0", touchPoint.x, touchPoint.y);
[self.view addSubview:dotView];
[self.view bringSubviewToFront:dotView];
NSLog(@"Added a dot.");
[dotView release];
}
The output in the log is:
Code:
[Session started at 2011-02-19 15:36:12 -0600.]
2011-02-19 15:36:28.560 TabBarApp[56894:207] Touches began!
2011-02-19 15:36:28.587 TabBarApp[56894:207] Touch point frame: x: 256 y: 286 w: 2.0 h: 2.0
2011-02-19 15:36:28.588 TabBarApp[56894:207] Added a dot.
Thanks!