PDA

View Full Version : Doubt in Touch event




iphonejudy
May 8, 2009, 04:43 AM
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([touch view] == baseImage1)
{

UIImage *anImage = [UIImage imageNamed:@"dragon1.png"];

}

}

baseImage1 -> Imageview

Can we specify touch event for the image with in the imageview?



BlackWolf
May 8, 2009, 06:04 AM
not if you use "touch" without declaring it, but generally that works, yes

iphonejudy
May 8, 2009, 06:42 AM
not if you use "touch" without declaring it, but generally that works, yes


I will explain you the problem.

I want to color the image,when the user touch the image.

I am having the image ,which is having a white space around(Normally a image having a white space know.because when we save an image.It would be save with a white rectangle .(surrounded the image) know?

My problem is the white space also considered as a image.Am i right?

So when the user touch outside of the image (white rectangle).The image will be colored.

Its a wrong thing.The image should be colored.when the user touch within the image.

Any solution?

BlackWolf
May 8, 2009, 07:07 AM
I will explain you the problem.

I want to color the image,when the user touch the image.

I am having the image ,which is having a white space around(Normally a image having a white space know.because when we save an image.It would be save with a white rectangle .(surrounded the image) know?

My problem is the white space also considered as a image.Am i right?

So when the user touch outside of the image (white rectangle).The image will be colored.

Its a wrong thing.The image should be colored.when the user touch within the image.

Any solution?

well, I guess the easiest solution would be to check for the position the user touched. if you know the size of the white border than you can easily determine weather the user really tapped the image or just the border. You can get the coordinated of the tap with
locationInView:
of UITouch. So if you border is 5px width the x coordinates of the tap need to be bigger than 5 and the y coordinates of the tap also need to be bigger than 5 - and then you are in the image.

oh and btw: wrap you code in code-tags, make more clear what you need to know next time and for god's sake post functional code! like I said above: the code you posted will not work because "touch" is undeclared!

iphonejudy
May 11, 2009, 08:52 AM
I have coordinates values in an array,I need to compare the array values with my touch coordinates

I used the below code.


CGPoint location = [touch locationInView:baseImage2];
float x=location.x;
float y=location.y;
int *a={(10,10),(20,20)};
if(location = a)
{
NSLog(@"I am touch");

}


But i got error.

BlackWolf
May 11, 2009, 08:56 AM
1) there is an obvious error in that code, I am not gonna tell you where
2) location is no array, it's a CGPoint. But even if you created another CGPoint, you cannot compare structures. you need to compare the x and y value seperatly.

iphonejudy
May 11, 2009, 09:08 AM
sorry.


ok.

I thought to do onething.that is,

Store all x and y coordinates of image in an array,

I need to compare the touchpoint(coordinates) with the array.

So we cant compare CGPoint with the array right?

Anyother idea compare my coordinates with coordinates in array?

BlackWolf
May 11, 2009, 10:22 AM
yeah, just don't compare the whole thing but rather compare the x and y values seperatly, like I said.

If you need to do that often, you can write a method that does that. though I would not compare a CGPoint with an array, but rather a CGPoint with a CGPoint, it's more logical.4

besides that, I just saw that your code says
int *a
int is not an object-type, you can't use pointers there. seems to me like you should really learn the basics again!

ChOas
May 11, 2009, 10:40 AM
Besides that


location = a


Is an assign, not a compare.

BlackWolf
May 11, 2009, 11:14 AM
Besides that


location = a


Is an assign, not a compare.

sssh, that was the obvious mistake I didn't wanna tell :D

iphonejudy
May 12, 2009, 05:23 AM
Hi,




CGRect area = CGRectMake(0, 0, testimage.size.width, testimage.size.height);


I want to check the touch event for the area?

Is it possible?

BlackWolf
May 12, 2009, 05:26 AM
Hi,




CGRect area = CGRectMake(0, 0, testimage.size.width, testimage.size.height);


I want to check the touch event for the area?

Is it possible?

yes, with simple mathematic or by creating a view on that position.

iphonejudy
May 12, 2009, 05:41 AM
CGRect area = CGRectMake(0, 0, testimage.size.width, testimage.size.height);

Its a area taken from my image;

if ([touch view] == area) //But we cannot assign like this know?
{

NSLog(@"I am your area");


}

BlackWolf
May 12, 2009, 06:00 AM
CGRect area = CGRectMake(0, 0, testimage.size.width, testimage.size.height);

Its a area taken from my image;

if ([touch view] == area) //But we cannot assign like this know?
{

NSLog(@"I am your area");


}

... seriously?
of course you cannot compare a UIView with a CGRect. Where is the sense in that?

If you really don't know this one, then start ALL the way back from the beginning and try to get the hang of the logic of programming. seems to me like you don't really know what you are doing, sorry. but this one is REALLY easy

iphonejudy
May 12, 2009, 06:04 AM
I want to take particular area from my image and i want to check the touch event with that

BlackWolf
May 12, 2009, 06:07 AM
I want to take particular area from my image and i want to check the touch event with that

I know.
Really, I'm all for helping new programmers and stuff, but I don't see the sense in doing any kind of thinking for you. this is just ... basic logic ... . you need to be able to figure these things out for yourself if you really want to accomplish anything. that's why I am not telling you how to do it but rather tell you to do the thinking this time!

iphonejudy
May 12, 2009, 06:12 AM
okay.Thanks

iphonejudy
May 12, 2009, 07:30 AM
okay.Thanks

I cant specify touch event to the area.

Can u give me any idea?

BlackWolf
May 12, 2009, 07:57 AM
I cant specify touch event to the area.

Can u give me any idea?

yes. basic math. if you want to check if the touch event is in an area, check if the coordinates of the touch are within that area. it's that simple.

iphonejudy
May 12, 2009, 08:43 AM
yes. basic math. if you want to check if the touch event is in an area, check if the coordinates of the touch are within that area. it's that simple.


yeah.I am trying to do this only

see my previous thread

I have coordinates values in an array,I need to compare the array values with my touch coordinates

I used the below code.


Code:

CGPoint location = [touch locationInView:baseImage2];
float x=location.x;
float y=location.y;
int *a={(10,10),(20,20)};
if(location = a)
{
NSLog(@"I am touch");

}


But i got error.
________________

BlackWolf
May 12, 2009, 09:16 AM
yeah.I am trying to do this only

see my previous thread

let's do this again: SEPERATLY. You CANNOT compare a CGPoint and an array, you have to compare the two coordinates SEPERATLY. SEPERATLY. SEPERATLY.

but your syntax is still plain wrong, if you keep it like that then nothing will help ^^

KardelSharpeye
May 12, 2009, 12:42 PM
try CGRectContainsPoint...