Anjaneyulu Battula
Anjaneyulu Battula

Reputation: 1960

iOS Autolayout storyboard ScrollView - button bottom of the scrollview is unable to clickable

Using Storyboard, in UIViewController using UIScrollView, UIView as content view

Scrollview Constraints - top, bottom, left, right
UIView as contentview constraints - top, bottom, left, right, equal width height to ViewController's View.

I am using these constraints, can anyone please help me out why button is not calling?

Upvotes: 0

Views: 855

Answers (2)

Anjaneyulu Battula
Anjaneyulu Battula

Reputation: 1960

Just now found the answer with removing any autolayout constraints, for content view we have to set constraints like below:

  • Top, bottom, left, right
  • Align CenterX - here we have to set the content view height then for that constraint we have to set constant as scrollview content size height

Upvotes: 0

MSU_Bulldog
MSU_Bulldog

Reputation: 3519

The button is not clickable because it is below the frame of the content view. You need to remove all auto layout constraints from your content view (the UIView inside the scrollview).

Then you can add all the objects that you need to add to the content view and set the height of the content view according to the height of the content.

So lets say that you calculated a height of 1000 for the content of the objects in the scroll view. You would then need to set the frame of the content view like this:

contentView.frame = CGRectMake(0,0,scrollView.frame.size.width, 1000);

And don't forget to set the contentSize for the scrollview so that the scrollview knows how much room it needs to scroll.

Upvotes: 0

Related Questions