PDA

View Full Version : UITouch




KardelSharpeye
May 7, 2009, 11:51 AM
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:@"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?



BlackWolf
May 7, 2009, 02:17 PM
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.

KardelSharpeye
May 7, 2009, 03:06 PM
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.

BlackWolf
May 7, 2009, 03:44 PM
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

jnic
May 8, 2009, 04:26 AM
how can i add and image ontop of another image and save it as one image.

Try something like:


// 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/library/documentation/UIKit/Reference/UIKitFunctionReference/Reference/reference.html

KardelSharpeye
May 8, 2009, 05:37 PM
thanks man that works perfectly!