0
votes

I have a UIScrollView with several buttons in it. The buttons at the bottom of the scrollview are visible, but don't respond when they're pressed. My problem appears to be the same as the one in this Stackoverflow Question, but the accepted answer does not seem to solve my problem; the frame of the scrollview, the contentSize of the scrollview, and the frame of the view inside the scrollview (which is also the superview of the problematic buttons) all have width 414pt and height 900pt. That should definitely be large enough to encompass the buttons which aren't responding.

EDIT: I created the scrollview in Interface Builder. The edges of the the container view within the scrollview are pinned to the edged of the scrollview.

I tried adding these lines of code:

    scrolling.frame = CGRect(x: 0, y: 0, width: 414, height: 900)
    viewInsideScrollview.frame = CGRect(x: 0, y: 0, width: 414, height: 900)
    scrolling.contentSize = CGSizeMake(414, 900)
    self.view.frame = CGRect(x: 0, y: 0, width: 414, height: 900)

Adding these lines didn't change how the scrollview looked or acted (scrolling fine, but with unresponsive buttons on the bottom.)

1
Are you sure button is one of scroll view's subviews?Lumialxk
Please provide some of your code or it will be impossible to give you a correct answer.user786033
I added some code in my edit.Olivia Watkins
You have not proved that viewInsideScrollview is a subview of scrolling (if that is the scroll view).matt
In Interface Builder, I can see that viewInsideScrollview is a subview of scrolling (which your right, that is the scrollview). The buttons I'm having trouble with are subviews of viewInsideScrollview.Olivia Watkins

1 Answers

1
votes

A UIScrollView infers its size by the view/views inside of it. You created your views in the interface builder so that could be why the lines of code you added did not work (I am not entirely sure why they did not). However, what will work is setting constraints on your viewInsideScrollview so that the scrolling expands to the full content size. For example, if you have 10 buttons in your viewInsideScrollview, you should set a top space constraint on the top most button, leading and trailing constraints, constraints to give spacing in between buttons, and a bottom space constraint on the bottom most button. The scrolling will expand to accommodate all of the buttons, and you will be able to select all of them.