Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

KardelSharpeye

macrumors member
Original poster
Apr 28, 2009
56
0
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?
 
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.
 
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.
 
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.

I would have answered that if I knew how ;-) I did not work a lot with images so far, so no idea
 
how can i add and image ontop of another image and save it as one image.

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.