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

iphonejudy

macrumors 6502
Original poster
Sep 12, 2008
301
1
Code:
-(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?
 
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?
 
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!
 
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.
 
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.
 
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?
 
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!
 
Hi,




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

I want to check the touch event for the area?

Is it possible?
 
CGRect area = CGRectMake(0, 0, testimage.size.width, testimage.size.height);

Its a area taken from my image;

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

NSLog(@"I am your area");


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

Its a area taken from my image;

Code:
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
 
I want to take particular area from my image and i want to check the touch event with that
 
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!
 
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.
________________
 
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 ^^
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.