tags:

views:

34

answers:

1

hi, I'm trying to figure out what i'm doing wrong but i just don't get it. Here is what i want to do:

I want to draw a circle somewhere on the screen of the iphone and then i want the circle always to be displayed at the position where the user currently taps on the screen. I started by creating a subclass of UIView and adding the following lines into the "drawRect" method:

- (void)drawRect:(CGRect)rect {

//Create the main view!

 CGContextRef mainscreen = UIGraphicsGetCurrentContext();

 //Draw the dot
 //will be a circle cause rectangle is a square
 CGRect dotRect = CGRectMake(50, 80, 100, 100);
 [[UIColor blueColor] set];
 CGContextStrokeEllipseInRect(mainscreen, dotRect);
 CGContextFillEllipseInRect(mainscreen, dotRect);

}

The appears just fine but now i have no idea how to make it move around on the screen i've tried serveral things and nothing worked pls help!

+1  A: 

To draw the dot in a different location, change the origin of dotRect. To figure out where to draw it, implement -touchesBegan:withEvent: and -touchesMoved:withEvent: and record the location where the touches are occuring.

NSResponder
and call setNeedsDisplay every time you change the origin.
drawnonward
yea but where exactly do i put the code? because for now i just implemented the three methods thouchBegan, touchEnded etc in the UIview subclass and then i put code into the viewControler class to make buttons do certain actions change label's text etc..And i did that by creating serveral IBOutlets for the objects i created in interface bulider. i don't really know how to access the circle through the view controller since it's not really an object created by interface builder!?
Christoph v
alright now i implemented the following: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; center1 = [touch locationInView:self]; [self setNeedsDisplay];}but its still not working......
Christoph v