Discussion in 'iOS Programming' started by KardelSharpeye, May 7, 2009.

  1. KardelSharpeye macrumors member


    Apr 28, 2009

    I am trying to use the UITouch and i have followed the tutorial. My file format is a bit different than the one on the tutorial out there. however, I do have a UIImageView image on a view. but when i use the function "touchesBegan" and click on the view, everywhere i click including on the UIImageView image. it only say that i am clicking on the view...

    This is how i implemented my UITouch:
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    NSLog(@"view=%@", [touch view]);
    NSLog(@"image=%@", image);

    and when i touch the image and outside of the image, i only get one result:
    view=<MyView: 0x529100>
    image=<UIImageView: 0x52a690>

    i am not sure is it because my IBOutlet on the image is wrong? please help.

    in my header i have:
    UIImageView *image;
    @property (nonatomic, retain) UIImageView *image;

    and in my implementation file i have:
    UIImageView *temp = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 70.0, 70.0)];
    temp.image = [UIImage imageNamed:mad:"image.jpg"];
    self.image = temp;
    [temp release]
    [self addSubview:image];

    Is there anyway i can manually connect my image to the view instead of making a UIImageView int the Interface Builder and connect it?
  2. BlackWolf macrumors regular

    Apr 9, 2009
    of course you can manually connect them. you can manually (programatically) do ANYTHING.
    just use
    of UIImageView.

    to get back to your problem: I can't see anything wrong with your code. I have an almost identical code in my apps and it works.

    I would guess that "userInteractionEnabled" is set to NO for your UIImageView, which causes it to not react to user interaction.
  3. KardelSharpeye thread starter macrumors member


    Apr 28, 2009
    yes that works!!! awesome thanks man. by the way can you respond to the other post that i had up regarding image editing. like how can i add and image ontop of another image and save it as one image. anyhelp is greatly appreciated.
  4. BlackWolf macrumors regular

    Apr 9, 2009
    I would have answered that if I knew how ;-) I did not work a lot with images so far, so no idea
  5. jnic macrumors 6502a

    Oct 24, 2008
    Try something like:

    // Size of the new image.
    CGSize size = CGSizeMake(width, height);
    // Context.
    CGContextRef context = UIGraphicsGetCurrentContext();
    // Your images here.
    UIImage *image1;
    UIImage *image2;
    // Draw them to the context.
    [image1 drawInRect:CGRectMake(x, y, width, height)];
    [image2 drawInRect:CGRectMake(x, y, width, height)];
    // Construct the image from the context and return it.
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    return newImage; // The thing you want.
    Docs: http://developer.apple.com/iPhone/l...KitFunctionReference/Reference/reference.html
  6. KardelSharpeye thread starter macrumors member


    Apr 28, 2009

Share This Page