0

I use uiscrollview and when I click button in scrollview I add text in textView and then button outside view so... when button outside view I scroll down and can't click the button. My code:

change scrollView height:

scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 1000);

enter image description here

YakovL
  • 7,557
  • 12
  • 62
  • 102
user3546854
  • 349
  • 1
  • 4
  • 12
  • check autoresizing for all view inside Scrollview. your button is visible but in actual it is not. And also make sure your button have User interaction YES . for checking your Button is visible or not .see my ans below – Shubham bairagi Jan 29 '16 at 13:45
  • Possible duplicate of [UIButton does not work when it in UIScrollView](http://stackoverflow.com/questions/16649639/uibutton-does-not-work-when-it-in-uiscrollview) – shpasta Jan 29 '16 at 17:22

4 Answers4

2

You could try setting the delaysContentTouches to false on your UIScrollView.

UIScrollView

Laffen
  • 2,753
  • 17
  • 29
2

In my case, when button is into a subview -> into a ScrollView, the tap will not be cached, non matter what scroll view settings you have..

So I added the button as subview of my scrollView and tap was fired

scrollView.addSubview(button)
Hugo Perez
  • 481
  • 8
  • 10
  • Although it's against the guidelines of this website, I have to thank you. Your warning about having the button inside a view that's inside the scrollview not working is what _fixed_ my problem. Always thought that the scrollview should only have one subview, but I may have inherited that habit from Android. – auhmaan Dec 17 '18 at 16:15
0
CGRect frameforMainView = mainView.frame;
frameforMainView.size.height = viewFirstAnswerButton.frame.origin.y + viewFirstAnswerButton.frame.size.height;
mainView.frame = frameforMainView;

//Now Set ContentSize Of scroll view;
[scrollView setContentSize:CGSizeMake(0, mainView.frame.origin.y + mainView.frame.size.height)];

if you are using Autolayouts then don't forget to add translatesAutoresizingMaskIntoConstraints = YES

Shubham bairagi
  • 943
  • 7
  • 25
0

Drag all subviews from mainView to ScrollView. And hide the mainView. Make sure mainView(ContainerView of scrollView) should also be a subView of scrollView.

Jeet
  • 59
  • 1
  • 4