Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get click event on subview on main uiview

I have a view which has scrolling images + paging. I have added these images on a UIVIEW and have added this UIView to main view. I want to detect click event on images within scrollview and handle them in main view.

How do I do it?

Please help

like image 979
iOSDev Avatar asked Nov 29 '22 09:11

iOSDev


2 Answers

You can solve the problem with a gesture recognizer.

// In the view controller where you create the subviews
// (not sure from your question, but I think you are adding image views to a scroll view

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake...];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewTapped:)];
[imageView addGestureRecognizer:tap];

Now, this will get called when the image view gets tapped

- (void)imageViewTapped:(UITapGestureRecognizer *)gr {

    UIImageView *theImageViewThatGotTapped = (UIImageView *)gr.view;
}
like image 141
danh Avatar answered Dec 08 '22 13:12

danh


Use Gesture simple one

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake...];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewTapped:)];
[imageView addGestureRecognizer:tap];

And call the selector method and do what ever u want..

like image 32
Shahnawaz Adil Avatar answered Dec 08 '22 12:12

Shahnawaz Adil