UITouch

Discussion in 'iPhone/iPad Programming' started by KardelSharpeye, May 7, 2009.

  1. macrumors member

    KardelSharpeye

    Joined:
    Apr 28, 2009
    #1
    Hello,

    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.

    EDIT:
    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];

    EDIT2:
    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. macrumors regular

    Joined:
    Apr 9, 2009
    #2
    of course you can manually connect them. you can manually (programatically) do ANYTHING.
    just use
    initWithImage:
    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. thread starter macrumors member

    KardelSharpeye

    Joined:
    Apr 28, 2009
    #3
    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. macrumors regular

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

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #5
    Try something like:

    Code:
    // Size of the new image.
    CGSize size = CGSizeMake(width, height);
    
    // Context.
    UIGraphicsBeginImageContext(size);
    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();
    UIGraphicsEndImageContext();
    
    return newImage; // The thing you want.
    
    Docs: http://developer.apple.com/iPhone/l...KitFunctionReference/Reference/reference.html
     
  6. thread starter macrumors member

    KardelSharpeye

    Joined:
    Apr 28, 2009
    #6
    thanks man that works perfectly!
     

Share This Page