-1

I'm facing an annoying problem with UIScrollView that my buttons cannot be touched if they are outside of the scroll view but I dont know how to fix it now

I have tried some ways but no helps so far

    override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    var contentRect = CGRect.zero

    for view in scrollContentView.subviews {
        contentRect = contentRect.union(view.frame)
    }

    for view in scrollContentView.subviews {
        contentRect = contentRect.union(view.frame)
    }

    scrollView.contentSize.height = contentRect.size.height
}

The code above just helps to make the scroll view scrollable

enter image description here

I also attached my sample project in this link https://drive.google.com/open?id=19U8jecDNQbAnTFbG36KMRxHfaLLcaLDq

I strongly appreciate your advices. Thank you

Uni
  • 187
  • 2
  • 7
  • 18
  • I know that can you give me some ideas to fix my problem? I guess it's constrains problems but not sure. What am I looking for now is a solution. Thanks – Uni Oct 07 '18 at 13:47
  • My problem is I added a stackview inside a scrollview to make it scrollable. The content of the stackview is bigger than the screen height & when I scroll the scrollview til the bottom. Some buttons are not touchable by fingers. These untouchable buttons are important – Uni Oct 07 '18 at 14:00

1 Answers1

1

You have not described your view hierarchy correctly. What you actually have is this:

Scroll view
    Content view
        Stack view
            Buttons

The content view is what is causing the problem. Its height is pinned to the height of the view controller's main view — which is the height of the screen. But of course the stack view with its buttons is taller than the screen, in order to give you something to scroll to. So the lower part of the stack view, and the buttons at the bottom of the stack view, are below the bottom of the content view. Thus they are outside their superview. Thus they are untouchable. A view outside its superview (or its superview, or its superview, all the way up the view hierarchy) is untouchable.

matt
  • 515,959
  • 87
  • 875
  • 1,141