Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does touchesBegan stop working when UIImageView in placed inside a UIScrollView?

UIView -> UIImageView

I know I have things somewhat working ok since I can tap on my UIImageView and see an NSLog() statement in my touchesBegan method.

.

UIView -> UIScrollView -> UIImageView

I drag that same UIImageView into a UIScrollView and touchesBegan no longer gets called when I tap on my UIImageView. (I haven't changed anything else. All the same connections, methods, and code remains unchanged.)

Why does touchesBegan no longer work? And what can I do to get it working again?

like image 202
Irene Avatar asked Dec 29 '22 03:12

Irene


2 Answers

Add uitapgesture to get event

Code is

  UITapGestureRecognizer *ges11=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Handeltap:)];
  [imagename addGestureRecognizer:ges11];

Create one action name "Handeltap" U will get called there.

like image 145
GameLoading Avatar answered Feb 08 '23 23:02

GameLoading


by default UIImageView don't handle user gestures. set UIImageView instance's userInteractionEnabled to YES

like image 29
xhan Avatar answered Feb 09 '23 00:02

xhan