Need help with UITouch

Discussion in 'iOS Development' started by johnmabassa, Mar 16, 2009.

  1. johnmabassa

    johnmabassa Member

    Joined:
    Mar 16, 2009
    Messages:
    87
    Likes Received:
    0
    Hi,
    I was trying to make app with an image on a view and when I touches the image I want the part where I touched to be erased ( remaining picture stays on the screen).... I am able to retrieve the position where I touched.....with in touchesbegan function but I am not sure how to make that part to disappear...

    please help

    Thanks in advance
    -John
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Just use CoreGraphics and cut it out.
  3. johnmabassa

    johnmabassa Member

    Joined:
    Mar 16, 2009
    Messages:
    87
    Likes Received:
    0
    Can u help me with some code snippets.....??
  4. johnmabassa

    johnmabassa Member

    Joined:
    Mar 16, 2009
    Messages:
    87
    Likes Received:
    0
    Waiting.....................

    Please Register or Log in to view images

  5. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Skylar will answer fast if he wants to help, or feels it is necessary for him to help. Here, clearly it is not. He is not writing you an application.
  6. johnmabassa

    johnmabassa Member

    Joined:
    Mar 16, 2009
    Messages:
    87
    Likes Received:
    0
    Okay!! I found a workaround for this.... (please forgive me if I am talking crap)
    I created a rect inside my touchesbegan method and called CGContextClearRect(context,selected);

    It removed the pixels but doesnt give a look that you are erasing it

    Please Register or Log in to view images



    Here is my code
    Code:
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    	CGContextRef context = UIGraphicsGetCurrentContext();
    	UITouch *touch = [touches anyObject];
    	CGPoint location = [touch locationInView:self];
    	selection=CGRectMake(location.x,location.y,15,15);
    	[self setNeedsDisplayInRect:selection];
    }
    and in my drawRect

    Code:
    - (void)drawRect:(CGRect)rect {
        // Drawing code
        CGContextRef ctx = UIGraphicsGetCurrentContext();
    	CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
    	UIImage *image=[UIImage imageNamed:@"fighter.png"] ;
    	CGRect rect2=CGRectMake(0,0, 300,300);
    	[image drawInRect:rect2];
    	CGContextClearRect(ctx, selection);
    }
    Can any one help me now??
  7. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Unrelated: you're leaking memory.
  8. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Yes, but who is to say he's not planning on fixing that later? I believe it was yourself that clearly said that as bad of a habit as it is, you don't take care of memory management while testing things.
  9. johnmabassa

    johnmabassa Member

    Joined:
    Mar 16, 2009
    Messages:
    87
    Likes Received:
    0
    I havent thought of memory leaks for time being, I was just concentrating on the functionality.....once I finish it successfully I will go back and try to fix the issues.......

Share This Page