Hello, i have a question. I do everything follow the tutorial then build and run very good. But when i zoom in the "drawImage" object by multi touch on screen then i draw very slow and my app have CRASH. anyone know that reason? Help me! this is my TouchBegan method Code: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { touches = [event allTouches]; switch ([touches count]) { case 1: { //Single touch } break; case 2: { //Multi Touch //Track the initial distance between two fingers. UITouch *touch1 = [[touches allObjects] objectAtIndex:0]; UITouch *touch2 = [[touches allObjects] objectAtIndex:1]; initialDistance = [self distanceBetweenTwoPoints:[touch1 locationInView:[self drawImage]] toPoint:[touch2 locationInView:[self drawImage]]]; } break; } } and touchMoved Method Code: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { touches = [event allTouches]; switch ([touches count]) { case 2: { //The image is being zoomed in or out. UITouch *touch1 = [[touches allObjects] objectAtIndex:0]; UITouch *touch2 = [[touches allObjects] objectAtIndex:1]; //Calculate the distance between the two fingers. finalDistance = [self distanceBetweenTwoPoints:[touch1 locationInView:[self drawImage]] toPoint:[touch2 locationInView:[self drawImage]]]; //Check if zoom in or zoom out. if(initialDistance > finalDistance&& drawImage.frame.size.width >160 && drawImage.frame.size.height >300) { //here decreasing the rect width,height drawImage.frame = CGRectMake(0,0, drawImage.frame.size.width - (initialDistance-finalDistance), drawImage.frame.size.height - (initialDistance-finalDistance)); drawImage.center = CGPointMake(160,230); initialDistance = finalDistance; } else if(initialDistance < finalDistance && drawImage.frame.size.width <740 && drawImage.frame.size.height < 880 ){ //here increasing the rect width,height drawImage.frame = CGRectMake(0,0, drawImage.frame.size.width + (finalDistance-initialDistance), drawImage.frame.size.height + (finalDistance-initialDistance)) ; drawImage.center = CGPointMake(160,230); initialDistance = finalDistance; } } break; } } Best Regards! ------------------double post merged------------------ may be this code can help you Code: CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
If I put the following line of code in my Clear button the screen be cleared of all he stuff the draw on the screen ? Code: CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear); How about allowing drawing on a certain section of the screen ?
if you put this code before you are drawing line on the screen(an UIImageView), then instead you draw a line on screen, you will erase screen under the line you have just draw. Code: [COLOR="Red"]CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);[/COLOR] //CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); CGContextStrokePath(UIGraphicsGetCurrentContext()); . . . This code like a trick.
seems no one wants to help me solve this problem. OK. I will ignore that. not allowed zoom in or zoom out. But how can i undo the picture after draw in it...?
this is a great post and works perfectly...i've been wrestling with it however for drawing in a rotated view. when i rotate to landscape the drawing is offset from the touch point by a significant factor, but the factor changes as i move my cursor around the screen. i suspect a scaling or content mode issue, but after countless hours and open ticket with apple developer support, i'm not getting anywhere. any one get this or a variant working in landscpape? ------------------double post merged------------------drawImage.image = nil;
go back to older state Hi, it's possible to go back to older state or undo? I've found CGContextSaveGState and CGContextRestoreGState but I don't know if is the way to do that and how to implement it Thanks!
It is absolutely possible to undo: http://www.youtube.com/watch?v=q4SNWq9t3W0 EDIT: Although, I'm not using this code to draw.
Build Errors Hi Skylar Thanks for the tutorial - this is exactly what I have been looking for. When I ran it the first time in the simulator, I got 157 errors. I got hat fixed and it worked good. I connected my iPad to it to run on the device, but I get two build errors I am not sure how to fix. They are: CFBundleIdentifier contains an illegal character and invalid bundle identifier I am not sure if this is your code or me at my end? Any ideas ? Iain
The CFBundleIdentifier is in your Info.plist. That error's on you. It's the com.yourapp.name. Go in and change that to all valid characters.