Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

touchesBegan in UIView not being called

I know that this question must have been answered plenty of times already, but I have no idea why the touchesBegan: is not called in my UIView.

Before I added it in my app, I made a trial project to do some tests. What I did was subclass a UIView where the touchesBegan: is implemented and add this as a subview of another view. The superview has a button which shows the subclassed UIView once clicked. Everything works as expected.

However, when I did the same thing in my existing app, the touchesBegan: method, as well as the touchesMoved:, were never called. Can anyone explain what could be preventing the methods from being called?

like image 287
Anna Fortuna Avatar asked Jul 10 '12 11:07

Anna Fortuna


2 Answers

I just found the answer to this. I realised that the superview of the UIView has the userInteraction set to disabled (which is the default value). So when I enabled the userInteraction of the superview, the touches are now recognised.

like image 82
Anna Fortuna Avatar answered Jan 03 '23 17:01

Anna Fortuna


In my case background = UIColor.clearColor() was the reason why touchesBegan was not called. Its obviously not called on transparent elements.

like image 34
David Avatar answered Jan 03 '23 17:01

David