2
votes

I have added the view programmatically in the main view. And in the parent view i am adding imageview as a subview programmatically. Now I have set the touch event for imageview on click but its not working. It is not detecting the touch event on click. I am using the following code of touch event of imageview.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [touches anyObject];

if ([touch view] == originalphoto)
{
    [fullview setHidden:NO];
    [self.view addSubview:fullview];
    [setimage setImage:image];
}

}

Do anyone has idea that how to set touch event of imageview which has been added programmatically?

Thanks alot.

4
In which UIImageView touch is not working? Is it originalphoto? or fullview?Krrish

4 Answers

1
votes

//Add gesture to your view

UITapGestureRecognizer *Tap= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ResignResponder:)];
[tempV addGestureRecognizer:Tap];

[Tap release];

//method will be called on tapping the view
-(void)ResignResponder:(UIGestureRecognizer*)recognizer {
        [LocSearchField resignFirstResponder];
        [self.view sendSubviewToBack:tempV];
 }
2
votes

Why dont you use a gesture? it is lot easier. You could use the UITapGestureRecognizer and let it work for you: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITapGestureRecognizer_Class/Reference/Reference.html

1
votes
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:UIIMAGEVIEW];// uiimageview object
touchx = location.x;
touchy = location.y;
NSLog(@" x= %i ", touchx);
NSLog(@"y = %i",touchy);
0
votes

Maybe you need to set property imageView.userInteractionEnabled = YES?