1

So I have A UIButton in a UIView within a UIScrollView within a UIViewController within a UIScrollView.. that is whole lot of layers I know but that was required. But the result I got is that the UIButton cannot be tapped because the touch can't be detected on the button. ScrollViews are working perfectly but the elements in the final layer are not detecting touches.

The Layers are as follow:

UIViewController
~UIScrollView
~~UIViewController
~~~UIScrollView
~~~~UIView
~~~~~UIButton

Kindly tell me how can I detect the touch on the last UIView?

1
  • see the frames of all your view by set background color , see clips to bounds of all Commented May 9, 2016 at 11:23

2 Answers 2

2

you should debug view hierarchy by clicking debug view hierarchy button

enter image description here look like this.

So you come to know that your button actually get touch events or it is hidden by other views.

Update :

I am uploading another screenshot

enter image description here

You have to run your project then you will able to see this button above console pane.

You can refer Apple documentation for more details.

Hope this will help :)

Sign up to request clarification or add additional context in comments.

2 Comments

Where is this button in xcode? I am unable to find it. thanks
Check my update in answer. you need to run your project in simulator then after you will find it above console
0
  1. To solve your current problem, you need to iterate through all gestures on each super view and call requireGestureRecognizerToFail for relevant gestures on subviews. This way you make sure that the subviews get the touches 'first' and superviews handle only those touches which are ignored or not recognize by subviews for whatever reason. (I know this sounds as ridiculous as having a view hierarchy like UIViewController -> UIScrollView -> UIViewController -> UIScrollView -> UIView -> UIButton)

  2. It seems unlikely that you could not have solved your visual design using either UITableView or UICollectionView. So reconsider!! It will save you a lot of such issues.

1 Comment

How should I call 'requireGestureRecognizerToFail' function in any class? couldn't find help through the apple documentation. also, I have used UICollectionView in the same project but that was not helping for the above scenario. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.